TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
auto_assign_subscript.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 "
./function.hpp
"
15
#include "
./utils.hpp
"
16
#include "
./placeholder.hpp
"
17
#include "
../macros.hpp
"
18
19
#include <functional>
20
#include <tuple>
21
#include <utility>
22
23
namespace
nda::clef {
24
29
30
// Delete the generic version so that every supported type has to implement its own version.
31
template
<
typename
T,
typename
RHS>
32
FORCEINLINE
void
clef_auto_assign_subscript
(T, RHS) =
delete
;
33
44
template
<
typename
T,
typename
RHS>
45
FORCEINLINE
void
clef_auto_assign_subscript
(std::reference_wrapper<T> wrapper, RHS &&rhs) {
46
clef_auto_assign_subscript
(wrapper.get(), std::forward<RHS>(rhs));
47
}
48
59
template
<
typename
T,
typename
RHS>
60
FORCEINLINE
void
clef_auto_assign_subscript
(
expr<tags::terminal, T>
const
&ex, RHS &&rhs) {
61
clef_auto_assign_subscript
(std::get<0>(ex.
childs
), std::forward<RHS>(rhs));
62
}
63
75
template
<
typename
Tag,
typename
... Childs,
typename
RHS>
76
FORCEINLINE
void
clef_auto_assign_subscript
(
expr<Tag, Childs...>
const
&ex, RHS
const
&rhs) {
77
ex << rhs;
78
}
79
80
// Overload of `clef_auto_assign_subscript` for rvalue references of generic expressions.
81
template
<
typename
Tag,
typename
... Childs,
typename
RHS>
82
FORCEINLINE
void
clef_auto_assign_subscript
(
expr<Tag, Childs...>
&&ex, RHS
const
&rhs) {
// NOLINT (is the rvalue reference overload needed?)
83
ex << rhs;
84
}
85
98
template
<
typename
T,
typename
RHS,
int
... Is>
99
FORCEINLINE
void
operator<<
(
expr
<
tags::subscript
, T,
placeholder<Is>
...>
const
&ex, RHS &&rhs) {
100
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
101
clef_auto_assign_subscript
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs),
placeholder<Is>
()...));
102
}
103
104
// Overload of nda::clef::operator<< for rvalue reference expressions.
105
template
<
typename
F,
typename
RHS,
int
... Is>
106
FORCEINLINE
void
operator<<
(
expr
<tags::subscript, F, placeholder<Is>...> &&ex, RHS &&rhs) {
// NOLINT (is the rvalue reference overload needed?)
107
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
108
clef_auto_assign_subscript
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs), placeholder<Is>()...));
109
}
110
111
// Overload of nda::clef::operator<< for lvalue reference expressions.
112
template
<
typename
F,
typename
RHS,
int
... Is>
113
FORCEINLINE
void
operator<<
(expr<tags::subscript, F, placeholder<Is>...> &ex, RHS &&rhs) {
114
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
115
clef_auto_assign_subscript
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs), placeholder<Is>()...));
116
}
117
118
// Delete functions to avoid nonsensical cases, e.g. f[x_ + y_] = RHS.
119
template
<
typename
F,
typename
RHS,
typename
... T>
120
void
operator<<
(
expr<tags::subscript, F, T...>
&&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
121
template
<
typename
F,
typename
RHS,
typename
... T>
122
void
operator<<
(
expr<tags::subscript, F, T...>
&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
123
template
<
typename
F,
typename
RHS,
typename
... T>
124
void
operator<<
(
expr<tags::subscript, F, T...>
const
&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
125
127
128
}
// 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.
function.hpp
Provides functionality to turn lazy expressions into callable objects and to generally simplify the e...
nda::clef::operator<<
__inline__ void operator<<(expr< tags::function, F, placeholder< Is >... > const &ex, RHS &&rhs)
Assign values to the underlying object of a lazy function call expression.
Definition
auto_assign.hpp:95
nda::clef::clef_auto_assign_subscript
void clef_auto_assign_subscript(std::vector< T > &v, F f)
Overload of clef_auto_assign_subscript function for std::vector.
Definition
vector.hpp:50
nda::clef::make_function
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition
function.hpp:89
macros.hpp
Macros used in the nda library.
placeholder.hpp
Provides placeholders for the clef library.
nda::clef::expr
Single node of the expression tree.
Definition
expression.hpp:65
nda::clef::expr::childs
childs_t childs
Child nodes of the current expression node.
Definition
expression.hpp:70
nda::clef::placeholder
A placeholder is an empty struct, labelled by an int.
Definition
placeholder.hpp:51
nda::clef::tags::subscript
Tag for subscript expressions.
Definition
expression.hpp:31
nda::expr
Lazy binary expression for nda::ArrayOrScalar types.
Definition
arithmetic.hpp:96
nda
clef
auto_assign_subscript.hpp
Generated by
1.17.0