TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
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
19
namespace
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
{
92
return
expr<tags::subscript, placeholder, expr_storage_t<T>
>{
tags::subscript
{}, *
this
, std::forward<T>(t)};
93
}
94
};
95
106
template
<
int
N,
typename
T>
107
struct
pair
{
109
T
rhs
;
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
utils.hpp
Provides some utility functions and type traits for the CLEF library.
expression.hpp
Provides a basic lazy expression type for the clef library.
nda::clef::expr
Single node of the expression tree.
Definition
expression.hpp:65
nda::clef::pair
A pair consisting of a placeholder and its assigned value.
Definition
placeholder.hpp:107
nda::clef::pair::rhs
T rhs
Value assigned to the placeholder (can be an lvalue reference).
Definition
placeholder.hpp:109
nda::clef::pair::p
static constexpr int p
Integer label of the placeholder.
Definition
placeholder.hpp:112
nda::clef::pair::value_type
std::decay_t< T > value_type
Type of the value after applying std::decay.
Definition
placeholder.hpp:115
nda::clef::placeholder
A placeholder is an empty struct, labelled by an int.
Definition
placeholder.hpp:51
nda::clef::placeholder::index
static constexpr int index
Integer label.
Definition
placeholder.hpp:55
nda::clef::placeholder::operator[]
auto operator[](T &&t) const
Subscript operator.
Definition
placeholder.hpp:91
nda::clef::placeholder::operator=
pair< N, RHS > operator=(RHS &&rhs) const
Assign a value to the placeholder.
Definition
placeholder.hpp:65
nda::clef::placeholder::operator()
auto operator()(Args &&...args) const
Function call operator.
Definition
placeholder.hpp:78
nda::clef::tags::function
Tag for function call expressions.
Definition
expression.hpp:28
nda::clef::tags::subscript
Tag for subscript expressions.
Definition
expression.hpp:31
nda
clef
placeholder.hpp
Generated by
1.17.0