TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
expression.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2023 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: Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "./utils.hpp"
25
26#include <tuple>
27#include <utility>
28
29namespace nda::clef {
30
31 namespace tags {
32
39 struct function {};
40
42 struct subscript {};
43
45 struct terminal {};
46
48 struct if_else {};
49
51 struct unary_op {};
52
54 struct binary_op {};
55
58 } // namespace tags
59
75 template <typename Tag, typename... Ts>
76 struct expr {
78 using childs_t = std::tuple<Ts...>;
79
82
84 expr(expr const &) = default;
85
90 expr(expr &&ex) noexcept : childs(std::move(ex.childs)) {}
91
93 expr &operator=(expr const &) = delete;
94
96 expr &operator=(expr &&) = default;
97
104 template <typename... Us>
105 expr(Tag, Us &&...us) : childs(std::forward<Us>(us)...) {}
106
115 template <typename... Args>
116 auto operator[](Args &&...args) const {
117 return expr<tags::subscript, expr, expr_storage_t<Args>...>{tags::subscript(), *this, std::forward<Args>(args)...};
118 }
119
128 template <typename... Args>
129 auto operator()(Args &&...args) const {
130 return expr<tags::function, expr, expr_storage_t<Args>...>{tags::function(), *this, std::forward<Args>(args)...};
131 }
132 };
133
134 namespace detail {
135
136 // Specialization of ph_set for nda::clef::expr types.
137 template <typename Tag, typename... Ts>
138 struct ph_set<expr<Tag, Ts...>> : ph_set<Ts...> {};
139
140 // Specialization of is_lazy_impl for nda::clef::expr types (always true).
141 template <typename Tag, typename... Ts>
142 constexpr bool is_lazy_impl<expr<Tag, Ts...>> = true;
143
144 // Specialization of force_copy_in_expr_impl for nda::clef::expr types (always true).
145 template <typename Tag, typename... Ts>
146 constexpr bool force_copy_in_expr_impl<expr<Tag, Ts...>> = true;
147
148 } // namespace detail
149
152} // namespace nda::clef
Single node of the expression tree.
expr & operator=(expr const &)=delete
Copy assignment operator is deleted.
expr(expr &&ex) noexcept
Move constructor simply moves the child nodes from the source expression.
std::tuple< Ts... > childs_t
Tuple type for storing the child nodes.
auto operator[](Args &&...args) const
Subscript operator.
expr & operator=(expr &&)=default
Default move assignment operator.
expr(expr const &)=default
Default copy constructor.
expr(Tag, Us &&...us)
Construct an expression node with a given tag and child nodes.
childs_t childs
Child nodes of the current expression node.
auto operator()(Args &&...args) const
Function call operator.
Tag for binary operator expressions.
Tag for function call expressions.
Tag for conditional expressions.
Tag for subscript expressions.
Tag to indicate a terminal node in the expression tree.
Tag for unary operator expressions.
Lazy binary expression for nda::ArrayOrScalar types.
Provides some utility functions and type traits for the CLEF library.