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 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn
16
22#pragma once
23
24#include "./expression.hpp"
25#include "./utils.hpp"
26
27#include <type_traits>
28#include <utility>
29
30namespace nda::clef {
31
38 // Forward declarations.
39 template <int N, typename T>
40 struct pair;
42
60 template <int N>
61 struct placeholder {
62 static_assert(N >= 0 && N < 64, "Placeholder index must be in {0, 1, ..., 63}");
63
65 static constexpr int index = N;
66
74 template <typename RHS>
75 pair<N, RHS> operator=(RHS &&rhs) const { // NOLINT (we want to return a pair)
76 return {std::forward<RHS>(rhs)};
77 }
78
87 template <typename... Args>
88 auto operator()(Args &&...args) const {
89 return expr<tags::function, placeholder, expr_storage_t<Args>...>{tags::function{}, *this, std::forward<Args>(args)...};
90 }
91
100 template <typename T>
101 auto operator[](T &&t) const {
102 return expr<tags::subscript, placeholder, expr_storage_t<T>>{tags::subscript{}, *this, std::forward<T>(t)};
103 }
104 };
105
116 template <int N, typename T>
117 struct pair {
120
122 static constexpr int p = N;
123
125 using value_type = std::decay_t<T>;
126 };
127
128 namespace detail {
129
130 // Specialization of force_copy_in_expr_impl for nda::clef::placeholder types (always true).
131 template <int N>
132 constexpr bool force_copy_in_expr_impl<placeholder<N>> = true;
133
134 // Specialization of ph_set for nda::clef::placeholder types.
135 template <int N>
136 struct ph_set<placeholder<N>> {
137 static constexpr ull_t value = 1ull << N;
138 };
139
140 // Specialization of ph_set for nda::clef::pair types.
141 template <int N, typename T>
142 struct ph_set<pair<N, T>> : ph_set<placeholder<N>> {};
143
144 // Specialization of is_lazy_impl for nda::clef::placeholder types.
145 template <int N>
146 constexpr bool is_lazy_impl<placeholder<N>> = true;
147
148 } // namespace detail
149
152} // 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.