TRIQS/nda 2.0.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
50 template <int N>
51 struct placeholder {
52 static_assert(N >= 0 && N < 64, "Placeholder index must be in {0, 1, ..., 63}");
53
55 static constexpr int index = N;
56
64 template <typename RHS>
65 pair<N, RHS> operator=(RHS &&rhs) const { // NOLINT (we want to return a pair)
66 return {std::forward<RHS>(rhs)};
67 }
68
77 template <typename... Args>
78 auto operator()(Args &&...args) const {
79 return expr<tags::function, placeholder, expr_storage_t<Args>...>{tags::function{}, *this, std::forward<Args>(args)...};
80 }
81
90 template <typename T>
91 auto operator[](T &&t) const {
93 }
94 };
95
106 template <int N, typename T>
107 struct pair {
110
112 static constexpr int p = N;
113
115 using value_type = std::decay_t<T>;
116 };
117
118 namespace detail {
119
120 // Specialization of force_copy_in_expr_impl for nda::clef::placeholder types (always true).
121 template <int N>
122 constexpr bool force_copy_in_expr_impl<placeholder<N>> = true;
123
124 // Specialization of ph_set for nda::clef::placeholder types.
125 template <int N>
126 struct ph_set<placeholder<N>> {
127 static constexpr ull_t value = 1ull << N;
128 };
129
130 // Specialization of ph_set for nda::clef::pair types.
131 template <int N, typename T>
132 struct ph_set<pair<N, T>> : ph_set<placeholder<N>> {};
133
134 // Specialization of is_lazy_impl for nda::clef::placeholder types.
135 template <int N>
136 constexpr bool is_lazy_impl<placeholder<N>> = true;
137
138 } // namespace detail
139
141
142} // 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.