TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
auto_assign_subscript.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
41 // Delete the generic version so that every supported type has to implement its own version.
42 template <typename T, typename RHS>
43 FORCEINLINE void clef_auto_assign_subscript(T, RHS) = delete;
44
55 template <typename T, typename RHS>
56 FORCEINLINE void clef_auto_assign_subscript(std::reference_wrapper<T> wrapper, RHS &&rhs) {
57 clef_auto_assign_subscript(wrapper.get(), std::forward<RHS>(rhs));
58 }
59
70 template <typename T, typename RHS>
71 FORCEINLINE void clef_auto_assign_subscript(expr<tags::terminal, T> const &ex, RHS &&rhs) {
72 clef_auto_assign_subscript(std::get<0>(ex.childs), std::forward<RHS>(rhs));
73 }
74
86 template <typename Tag, typename... Childs, typename RHS>
87 FORCEINLINE void clef_auto_assign_subscript(expr<Tag, Childs...> const &ex, RHS const &rhs) {
88 ex << rhs;
89 }
90
91 // Overload of `clef_auto_assign_subscript` for rvalue references of generic expressions.
92 template <typename Tag, typename... Childs, typename RHS>
93 FORCEINLINE void clef_auto_assign_subscript(expr<Tag, Childs...> &&ex, RHS const &rhs) { // NOLINT (is the rvalue reference overload needed?)
94 ex << rhs;
95 }
96
109 template <typename T, typename RHS, int... Is>
110 FORCEINLINE void operator<<(expr<tags::subscript, T, placeholder<Is>...> const &ex, RHS &&rhs) {
111 static_assert(detail::all_different(Is...), "Error in clef operator<<: Two of the placeholders on the LHS are the same");
112 clef_auto_assign_subscript(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
113 }
114
115 // Overload of nda::clef::operator<< for rvalue reference expressions.
116 template <typename F, typename RHS, int... Is>
117 FORCEINLINE void operator<<(expr<tags::subscript, F, placeholder<Is>...> &&ex, RHS &&rhs) { // NOLINT (is the rvalue reference overload needed?)
118 static_assert(detail::all_different(Is...), "Error in clef operator<<: Two of the placeholders on the LHS are the same");
119 clef_auto_assign_subscript(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
120 }
121
122 // Overload of nda::clef::operator<< for lvalue reference expressions.
123 template <typename F, typename RHS, int... Is>
124 FORCEINLINE void operator<<(expr<tags::subscript, F, placeholder<Is>...> &ex, RHS &&rhs) {
125 static_assert(detail::all_different(Is...), "Error in clef operator<<: Two of the placeholders on the LHS are the same");
126 clef_auto_assign_subscript(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), placeholder<Is>()...));
127 }
128
129 // Delete functions to avoid nonsensical cases, e.g. f[x_ + y_] = RHS.
130 template <typename F, typename RHS, typename... T>
131 void operator<<(expr<tags::subscript, F, T...> &&ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
132 template <typename F, typename RHS, typename... T>
133 void operator<<(expr<tags::subscript, F, T...> &ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
134 template <typename F, typename RHS, typename... T>
135 void operator<<(expr<tags::subscript, F, T...> const &ex, RHS &&rhs) = delete; // NOLINT (no forwarding required here)
136
139} // 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 operator<<(expr< tags::function, F, placeholder< Is >... > const &ex, RHS &&rhs)
Assign values to the underlying object of a lazy function call expression.
void clef_auto_assign_subscript(std::vector< T > &v, F f)
Overload of clef_auto_assign_subscript function for std::vector.
Definition vector.hpp:61
__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 subscript expressions.
Lazy binary expression for nda::ArrayOrScalar types.