TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
auto_assign.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
40
template
<
typename
T,
typename
RHS>
41
FORCEINLINE
void
clef_auto_assign
(std::reference_wrapper<T> wrapper, RHS &&rhs) {
42
clef_auto_assign
(wrapper.get(), std::forward<RHS>(rhs));
43
}
44
55
template
<
typename
T,
typename
RHS>
56
FORCEINLINE
void
clef_auto_assign
(
expr<tags::terminal, T>
const
&ex, RHS &&rhs) {
57
clef_auto_assign
(std::get<0>(ex.
childs
), std::forward<RHS>(rhs));
58
}
59
71
template
<
typename
Tag,
typename
... Childs,
typename
RHS>
72
FORCEINLINE
void
clef_auto_assign
(
expr<Tag, Childs...>
const
&ex, RHS
const
&rhs) {
73
ex << rhs;
74
}
75
76
// Overload of `clef_auto_assign` for rvalue references of generic expressions.
77
template
<
typename
Tag,
typename
... Childs,
typename
RHS>
78
FORCEINLINE
void
clef_auto_assign
(
expr<Tag, Childs...>
&&ex, RHS
const
&rhs) {
// NOLINT (is the rvalue reference overload needed?)
79
ex << rhs;
80
}
81
94
template
<
typename
F,
typename
RHS,
int
... Is>
95
FORCEINLINE
void
operator<<
(
expr
<
tags::function
, F,
placeholder<Is>
...>
const
&ex, RHS &&rhs) {
96
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
97
clef_auto_assign
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs),
placeholder<Is>
()...));
98
}
99
100
// Overload of nda::clef::operator<< for rvalue reference expressions.
101
template
<
typename
F,
typename
RHS,
int
... Is>
102
FORCEINLINE
void
operator<<
(
expr
<tags::function, F, placeholder<Is>...> &&ex, RHS &&rhs) {
// NOLINT (is the rvalue reference overload needed?)
103
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
104
clef_auto_assign
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs), placeholder<Is>()...));
105
}
106
107
// Overload of nda::clef::operator<< for lvalue reference expressions.
108
template
<
typename
F,
typename
RHS,
int
... Is>
109
FORCEINLINE
void
operator<<
(expr<tags::function, F, placeholder<Is>...> &ex, RHS &&rhs) {
110
static_assert
(detail::all_different(Is...),
"Error in clef operator<<: Two of the placeholders on the LHS are the same"
);
111
clef_auto_assign
(std::get<0>(ex.childs),
make_function
(std::forward<RHS>(rhs), placeholder<Is>()...));
112
}
113
114
// Delete functions to avoid nonsensical cases, e.g. f(x_ + y_) << RHS.
115
template
<
typename
F,
typename
RHS,
typename
... T>
116
void
operator<<
(
expr<tags::function, F, T...>
&&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
117
template
<
typename
F,
typename
RHS,
typename
... T>
118
void
operator<<
(
expr<tags::function, F, T...>
&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
119
template
<
typename
F,
typename
RHS,
typename
... T>
120
void
operator<<
(
expr<tags::function, F, T...>
const
&ex, RHS &&rhs) =
delete
;
// NOLINT (no forwarding required here)
121
123
124
}
// 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::clef_auto_assign
__inline__ void clef_auto_assign(std::reference_wrapper< T > wrapper, RHS &&rhs)
Overload of clef_auto_assign function for std::reference_wrapper objects.
Definition
auto_assign.hpp:41
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::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::function
Tag for function call expressions.
Definition
expression.hpp:28
nda::expr
Lazy binary expression for nda::ArrayOrScalar types.
Definition
arithmetic.hpp:96
nda
clef
auto_assign.hpp
Generated by
1.17.0