TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
make_lazy.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 "./utils.hpp"
26
27#include <utility>
28
29namespace nda::clef {
30
44 template <typename T>
45 auto make_expr(T &&t) {
46 return expr<tags::terminal, expr_storage_t<T>>{tags::terminal(), std::forward<T>(t)};
47 }
48
56 template <typename T>
58 return expr<tags::terminal, std::decay_t<T>>{tags::terminal(), std::forward<T>(t)};
59 }
60
73 template <typename F, typename... Args>
74 auto make_expr_call(F &&f, Args &&...args)
75 requires(is_any_lazy<Args...>)
76 {
77 return expr<tags::function, expr_storage_t<F>, expr_storage_t<Args>...>{tags::function{}, std::forward<F>(f), std::forward<Args>(args)...};
78 }
79
92 template <typename T, typename... Args>
93 auto make_expr_subscript(T &&t, Args &&...args)
94 requires(is_any_lazy<Args...>)
95 {
96 return expr<tags::subscript, expr_storage_t<T>, expr_storage_t<Args>...>{tags::subscript{}, std::forward<T>(t), std::forward<Args>(args)...};
97 }
98
100#define CLEF_MAKE_FNT_LAZY(name) \
101 template <typename... A> \
102 auto name(A &&...__a) \
103 requires(nda::clef::is_any_lazy<A...>) \
104 { \
105 return make_expr_call([](auto &&...__b) -> decltype(auto) { return name(std::forward<decltype(__b)>(__b)...); }, std::forward<A>(__a)...); \
106 }
107
109#define CLEF_IMPLEMENT_LAZY_METHOD(TY, name) \
110 template <typename... A> \
111 auto name(A &&...__a) \
112 requires(nda::clef::is_any_lazy<A...>) \
113 { \
114 return make_expr_call( \
115 [](auto &&__obj, auto &&...__b) -> decltype(auto) { return std::forward<decltype(__obj)>(__obj).name(std::forward<decltype(__b)>(__b)...); }, \
116 *this, std::forward<A>(__a)...); \
117 }
118
120#define CLEF_IMPLEMENT_LAZY_CALL(...) \
121 template <typename... Args> \
122 auto operator()(Args &&...args) const & \
123 requires(nda::clef::is_any_lazy<Args...>) \
124 { \
125 return make_expr_call(*this, std::forward<Args>(args)...); \
126 } \
127 \
128 template <typename... Args> \
129 auto operator()(Args &&...args) & \
130 requires(nda::clef::is_any_lazy<Args...>) \
131 { \
132 return make_expr_call(*this, std::forward<Args>(args)...); \
133 } \
134 \
135 template <typename... Args> \
136 auto operator()(Args &&...args) && \
137 requires(nda::clef::is_any_lazy<Args...>) \
138 { \
139 return make_expr_call(std::move(*this), std::forward<Args>(args)...); \
140 }
141
144} // namespace nda::clef
Provides some utility functions and type traits for the CLEF library.
Provides a basic lazy expression type for the clef library.
auto make_expr(T &&t)
Create a terminal expression node of an object.
Definition make_lazy.hpp:45
auto make_expr_subscript(T &&t, Args &&...args)
Create a subscript expression from an object and a list of arguments.
Definition make_lazy.hpp:93
auto make_expr_call(F &&f, Args &&...args)
Create a function call expression from a callable object and a list of arguments.
Definition make_lazy.hpp:74
auto make_expr_from_clone(T &&t)
Create a terminal expression node of an object.
Definition make_lazy.hpp:57
typename detail::expr_storage_impl< T >::type expr_storage_t
Type trait to determine how a type should be stored in an expression tree, i.e. either by reference o...
Definition utils.hpp:148
constexpr bool is_any_lazy
Constexpr variable that is true if any of the given types is lazy.
Definition utils.hpp:156
Single node of the expression tree.
Tag for function call expressions.
Tag for subscript expressions.
Tag to indicate a terminal node in the expression tree.