TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
expression.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 "
./utils.hpp
"
14
15
#include <tuple>
16
#include <utility>
17
18
namespace
nda::clef {
19
20
namespace
tags {
21
26
28
struct
function
{};
29
31
struct
subscript
{};
32
34
struct
terminal
{};
35
37
struct
if_else
{};
38
40
struct
unary_op
{};
41
43
struct
binary_op
{};
44
46
47
}
// namespace tags
48
53
64
template
<
typename
Tag,
typename
... Ts>
65
struct
expr
{
67
using
childs_t
= std::tuple<Ts...>;
68
70
childs_t
childs
;
71
73
expr
(
expr
const
&) =
default
;
74
79
expr
(
expr
&&ex) noexcept :
childs
(std::move(ex.childs)) {}
80
82
expr
&
operator=
(
expr
const
&) =
delete
;
83
85
expr
&
operator=
(
expr
&&) =
default
;
86
93
template
<
typename
... Us>
94
expr
(Tag, Us &&...us) :
childs
(std::forward<Us>(us)...) {}
95
104
#ifdef __cpp_explicit_this_parameter
105
template
<
typename
Self,
typename
... Args>
106
auto
operator[]
(
this
Self &&self, Args &&...args) {
107
return
expr<tags::subscript, expr, expr_storage_t<Args>
...>{
tags::subscript
(), std::forward<Self>(self), std::forward<Args>(args)...};
108
}
109
#else
110
template
<
typename
... Args>
111
auto
operator[]
(Args &&...args)
const
& {
112
return
expr<tags::subscript, expr, expr_storage_t<Args>
...>{
tags::subscript
(), *
this
, std::forward<Args>(args)...};
113
}
114
template
<
typename
... Args>
115
auto
operator[]
(Args &&...args) & {
116
return
expr<tags::subscript, expr, expr_storage_t<Args>
...>{
tags::subscript
(), *
this
, std::forward<Args>(args)...};
117
}
118
119
template
<
typename
... Args>
120
auto
operator[]
(Args &&...args) && {
121
return
expr<tags::subscript, expr, expr_storage_t<Args>
...>{tags::subscript(), std::move(*
this
), std::forward<Args>(args)...};
122
}
123
#endif
124
133
#ifdef __cpp_explicit_this_parameter
134
template
<
typename
Self,
typename
... Args>
135
auto
operator()
(
this
Self &&self, Args &&...args) {
136
return
expr<tags::function, expr, expr_storage_t<Args>
...>{tags::function(), std::forward<Self>(self), std::forward<Args>(args)...};
137
}
138
#else
139
template
<
typename
... Args>
140
auto
operator()
(Args &&...args)
const
& {
141
return
expr<tags::function, expr, expr_storage_t<Args>
...>{
tags::function
(), *
this
, std::forward<Args>(args)...};
142
}
143
144
template
<
typename
... Args>
145
auto
operator()
(Args &&...args) & {
146
return
expr<tags::function, expr, expr_storage_t<Args>
...>{
tags::function
(), *
this
, std::forward<Args>(args)...};
147
}
148
149
template
<
typename
... Args>
150
auto
operator()
(Args &&...args) && {
151
return
expr<tags::function, expr, expr_storage_t<Args>
...>{tags::function(), std::move(*
this
), std::forward<Args>(args)...};
152
}
153
#endif
154
};
155
156
namespace
detail {
157
158
// Specialization of ph_set for nda::clef::expr types.
159
template
<
typename
Tag,
typename
... Ts>
160
struct
ph_set<expr<Tag, Ts...>> : ph_set<Ts...> {};
161
162
// Specialization of is_lazy_impl for nda::clef::expr types (always true).
163
template
<
typename
Tag,
typename
... Ts>
164
constexpr
bool
is_lazy_impl<expr<Tag, Ts...>> =
true
;
165
166
// Specialization of force_copy_in_expr_impl for nda::clef::expr types (always true).
167
template
<
typename
Tag,
typename
... Ts>
168
constexpr
bool
force_copy_in_expr_impl<expr<Tag, Ts...>> =
true
;
169
170
}
// namespace detail
171
173
174
}
// namespace nda::clef
utils.hpp
Provides some utility functions and type traits for the CLEF library.
nda::clef::expr
Single node of the expression tree.
Definition
expression.hpp:65
nda::clef::expr::operator=
expr & operator=(expr const &)=delete
Copy assignment operator is deleted.
nda::clef::expr::operator()
auto operator()(Args &&...args) const &
Function call operator.
Definition
expression.hpp:140
nda::clef::expr::expr
expr(expr &&ex) noexcept
Move constructor simply moves the child nodes from the source expression.
Definition
expression.hpp:79
nda::clef::expr::childs_t
std::tuple< Ts... > childs_t
Tuple type for storing the child nodes.
Definition
expression.hpp:67
nda::clef::expr::operator=
expr & operator=(expr &&)=default
Default move assignment operator.
nda::clef::expr::operator[]
auto operator[](Args &&...args) const &
Subscript operator.
Definition
expression.hpp:111
nda::clef::expr::expr
expr(expr const &)=default
Default copy constructor.
nda::clef::expr::expr
expr(Tag, Us &&...us)
Construct an expression node with a given tag and child nodes.
Definition
expression.hpp:94
nda::clef::expr::childs
childs_t childs
Child nodes of the current expression node.
Definition
expression.hpp:70
nda::clef::tags::binary_op
Tag for binary operator expressions.
Definition
expression.hpp:43
nda::clef::tags::function
Tag for function call expressions.
Definition
expression.hpp:28
nda::clef::tags::if_else
Tag for conditional expressions.
Definition
expression.hpp:37
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::tags::unary_op
Tag for unary operator expressions.
Definition
expression.hpp:40
nda
clef
expression.hpp
Generated by
1.17.0