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 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn
16
22#pragma once
23
24#include "./expression.hpp"
25#include "./function.hpp"
26#include "./utils.hpp"
27#include "./placeholder.hpp"
28#include "../macros.hpp"
29
30#include <functional>
31#include <tuple>
32#include <utility>
33
34namespace nda::clef {
35
51 template <typename T, typename RHS>
52 FORCEINLINE void clef_auto_assign(std::reference_wrapper<T> wrapper, RHS &&rhs) {
53 clef_auto_assign(wrapper.get(), std::forward<RHS>(rhs));
54 }
55
66 template <typename T, typename RHS>
67 FORCEINLINE void clef_auto_assign(expr<tags::terminal, T> const &ex, RHS &&rhs) {
68 clef_auto_assign(std::get<0>(ex.childs), std::forward<RHS>(rhs));
69 }
70
82 template <typename Tag, typename... Childs, typename RHS>
83 FORCEINLINE void clef_auto_assign(expr<Tag, Childs...> const &ex, RHS const &rhs) {
84 ex << rhs;
85 }
86
87 // Overload of `clef_auto_assign` for rvalue references of generic expressions.
88 template <typename Tag, typename... Childs, typename RHS>
89 FORCEINLINE void clef_auto_assign(expr<Tag, Childs...> &&ex, RHS const &rhs) { // NOLINT (is the rvalue reference overload needed?)
90 ex << rhs;
91 }
92
105 template <typename F, typename RHS, int... Is>
106 FORCEINLINE void operator<<(expr<tags::function, F, placeholder<Is>...> const &ex, RHS &&rhs) {
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(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
109 }
110
111 // Overload of nda::clef::operator<< for rvalue reference expressions.
112 template <typename F, typename RHS, int... Is>
113 FORCEINLINE void operator<<(expr<tags::function, F, placeholder<Is>...> &&ex, RHS &&rhs) { // NOLINT (is the rvalue reference overload needed?)
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(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
116 }
117
118 // Overload of nda::clef::operator<< for lvalue reference expressions.
119 template <typename F, typename RHS, int... Is>
120 FORCEINLINE void operator<<(expr<tags::function, F, placeholder<Is>...> &ex, RHS &&rhs) {
121 static_assert(detail::all_different(Is...), "Error in clef operator<<: Two of the placeholders on the LHS are the same");
122 clef_auto_assign(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
123 }
124
125 // Delete functions to avoid nonsensical cases, e.g. f(x_ + y_) << RHS.
126 template <typename F, typename RHS, typename... T>
127 void operator<<(expr<tags::function, F, T...> &&ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
128 template <typename F, typename RHS, typename... T>
129 void operator<<(expr<tags::function, F, T...> &ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
130 template <typename F, typename RHS, typename... T>
131 void operator<<(expr<tags::function, F, T...> const &ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
132
135} // 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:100
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.