TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
placeholder.hpp
Go to the documentation of this file.
1// Copyright (c) 2024--present, The Simons Foundation
2// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3// SPDX-License-Identifier: Apache-2.0
4// See LICENSE in the root of this distribution for details.
5
10
11#pragma once
12
13#include "./expression.hpp"
14#include "./utils.hpp"
15
16#include <type_traits>
17#include <utility>
18
19namespace nda::clef {
20
25
27 // Forward declarations.
28 template <int N, typename T>
29 struct pair;
31
49 template <int N>
50 struct placeholder {
51 static_assert(N >= 0 && N < 64, "Placeholder index must be in {0, 1, ..., 63}");
52
54 static constexpr int index = N;
55
63 template <typename RHS>
64 pair<N, RHS> operator=(RHS &&rhs) const { // NOLINT (we want to return a pair)
65 return {std::forward<RHS>(rhs)};
66 }
67
76 template <typename... Args>
77 auto operator()(Args &&...args) const {
78 return expr<tags::function, placeholder, expr_storage_t<Args>...>{tags::function{}, *this, std::forward<Args>(args)...};
79 }
80
89 template <typename T>
90 auto operator[](T &&t) const {
92 }
93 };
94
105 template <int N, typename T>
106 struct pair {
109
111 static constexpr int p = N;
112
114 using value_type = std::decay_t<T>;
115 };
116
117 namespace detail {
118
119 // Specialization of force_copy_in_expr_impl for nda::clef::placeholder types (always true).
120 template <int N>
121 constexpr bool force_copy_in_expr_impl<placeholder<N>> = true;
122
123 // Specialization of ph_set for nda::clef::placeholder types.
124 template <int N>
125 struct ph_set<placeholder<N>> {
126 static constexpr ull_t value = 1ull << N;
127 };
128
129 // Specialization of ph_set for nda::clef::pair types.
130 template <int N, typename T>
131 struct ph_set<pair<N, T>> : ph_set<placeholder<N>> {};
132
133 // Specialization of is_lazy_impl for nda::clef::placeholder types.
134 template <int N>
135 constexpr bool is_lazy_impl<placeholder<N>> = true;
136
137 } // namespace detail
138
140
141} // namespace nda::clef
Provides some utility functions and type traits for the CLEF library.
Provides a basic lazy expression type for the clef library.
Single node of the expression tree.
A pair consisting of a placeholder and its assigned value.
T rhs
Value assigned to the placeholder (can be an lvalue reference).
static constexpr int p
Integer label of the placeholder.
std::decay_t< T > value_type
Type of the value after applying std::decay.
A placeholder is an empty struct, labelled by an int.
static constexpr int index
Integer label.
auto operator[](T &&t) const
Subscript operator.
pair< N, RHS > operator=(RHS &&rhs) const
Assign a value to the placeholder.
auto operator()(Args &&...args) const
Function call operator.
Tag for function call expressions.
Tag for subscript expressions.