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) 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
18namespace 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
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 template <typename... Args>
105 auto operator[](Args &&...args) const {
106 return expr<tags::subscript, expr, expr_storage_t<Args>...>{tags::subscript(), *this, std::forward<Args>(args)...};
107 }
108
117 template <typename... Args>
118 auto operator()(Args &&...args) const {
119 return expr<tags::function, expr, expr_storage_t<Args>...>{tags::function(), *this, std::forward<Args>(args)...};
120 }
121 };
122
123 namespace detail {
124
125 // Specialization of ph_set for nda::clef::expr types.
126 template <typename Tag, typename... Ts>
127 struct ph_set<expr<Tag, Ts...>> : ph_set<Ts...> {};
128
129 // Specialization of is_lazy_impl for nda::clef::expr types (always true).
130 template <typename Tag, typename... Ts>
131 constexpr bool is_lazy_impl<expr<Tag, Ts...>> = true;
132
133 // Specialization of force_copy_in_expr_impl for nda::clef::expr types (always true).
134 template <typename Tag, typename... Ts>
135 constexpr bool force_copy_in_expr_impl<expr<Tag, Ts...>> = true;
136
137 } // namespace detail
138
140
141} // namespace nda::clef
Provides some utility functions and type traits for the CLEF library.
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.