TRIQS/nda 1.3.0
Multi-dimensional array library for C++
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
23namespace 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
Provides some utility functions and type traits for the CLEF library.
Provides a basic lazy expression type for the clef library.
Provides functionality to turn lazy expressions into callable objects and to generally simplify the e...
__inline__ void clef_auto_assign(std::reference_wrapper< T > wrapper, RHS &&rhs)
Overload of clef_auto_assign function for std::reference_wrapper objects.
__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.
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition function.hpp:89
Macros used in the nda library.
Provides placeholders for the clef library.
Single node of the expression tree.
childs_t childs
Child nodes of the current expression node.
A placeholder is an empty struct, labelled by an int.
Tag for function call expressions.
Lazy binary expression for nda::ArrayOrScalar types.