TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
make_lazy.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 "
./utils.hpp
"
15
16
#include <utility>
17
18
namespace
nda::clef {
19
24
33
template
<
typename
T>
34
auto
make_expr
(T &&t) {
35
return
expr<tags::terminal, expr_storage_t<T>
>{
tags::terminal
(), std::forward<T>(t)};
36
}
37
45
template
<
typename
T>
46
auto
make_expr_from_clone
(T &&t) {
47
return
expr<tags::terminal, std::decay_t<T>
>{
tags::terminal
(), std::forward<T>(t)};
48
}
49
62
template
<
typename
F,
typename
... Args>
63
auto
make_expr_call
(F &&f, Args &&...args)
64
requires
(
is_any_lazy
<Args...>)
65
{
66
return
expr<tags::function, expr_storage_t<F>
,
expr_storage_t<Args>
...>{
tags::function
{}, std::forward<F>(f), std::forward<Args>(args)...};
67
}
68
81
template
<
typename
T,
typename
... Args>
82
auto
make_expr_subscript
(T &&t, Args &&...args)
83
requires
(
is_any_lazy
<Args...>)
84
{
85
return
expr<tags::subscript, expr_storage_t<T>
,
expr_storage_t<Args>
...>{
tags::subscript
{}, std::forward<T>(t), std::forward<Args>(args)...};
86
}
87
89
#define CLEF_MAKE_FNT_LAZY(name) \
90
template <typename... A> \
91
auto name(A &&...__a) \
92
requires(nda::clef::is_any_lazy<A...>) \
93
{ \
94
return make_expr_call([](auto &&...__b) -> decltype(auto) { return name(std::forward<decltype(__b)>(__b)...); }, std::forward<A>(__a)...); \
95
}
96
98
#define CLEF_IMPLEMENT_LAZY_METHOD(TY, name) \
99
template <typename... A> \
100
auto name(A &&...__a) \
101
requires(nda::clef::is_any_lazy<A...>) \
102
{ \
103
return make_expr_call( \
104
[](auto &&__obj, auto &&...__b) -> decltype(auto) { return std::forward<decltype(__obj)>(__obj).name(std::forward<decltype(__b)>(__b)...); }, \
105
*this, std::forward<A>(__a)...); \
106
}
107
109
#define CLEF_IMPLEMENT_LAZY_CALL(...) \
110
template <typename... Args> \
111
auto operator()(Args &&...args) const & \
112
requires(nda::clef::is_any_lazy<Args...>) \
113
{ \
114
return make_expr_call(*this, std::forward<Args>(args)...); \
115
} \
116
\
117
template <typename... Args> \
118
auto operator()(Args &&...args) & \
119
requires(nda::clef::is_any_lazy<Args...>) \
120
{ \
121
return make_expr_call(*this, std::forward<Args>(args)...); \
122
} \
123
\
124
template <typename... Args> \
125
auto operator()(Args &&...args) && \
126
requires(nda::clef::is_any_lazy<Args...>) \
127
{ \
128
return make_expr_call(std::move(*this), std::forward<Args>(args)...); \
129
}
130
132
133
}
// 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.
nda::clef::make_expr
auto make_expr(T &&t)
Create a terminal expression node of an object.
Definition
make_lazy.hpp:34
nda::clef::make_expr_subscript
auto make_expr_subscript(T &&t, Args &&...args)
Create a subscript expression from an object and a list of arguments.
Definition
make_lazy.hpp:82
nda::clef::make_expr_call
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:63
nda::clef::make_expr_from_clone
auto make_expr_from_clone(T &&t)
Create a terminal expression node of an object.
Definition
make_lazy.hpp:46
nda::clef::expr_storage_t
typename detail::expr_storage_impl< T >::type expr_storage_t
Type trait to determine whether a type should be stored in an expression tree by reference or by valu...
Definition
utils.hpp:136
nda::clef::is_any_lazy
constexpr bool is_any_lazy
Constexpr variable that is true if any of the given types is lazy.
Definition
utils.hpp:144
nda::clef::expr
Single node of the expression tree.
Definition
expression.hpp:65
nda::clef::tags::function
Tag for function call expressions.
Definition
expression.hpp:28
nda::clef::tags::subscript
Tag for subscript expressions.
Definition
expression.hpp:31
nda::clef::tags::terminal
Tag to indicate a terminal node in the expression tree.
Definition
expression.hpp:34
nda
clef
make_lazy.hpp
Generated by
1.17.0