TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
function.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
23#pragma once
24
25#include "./eval.hpp"
26#include "./utils.hpp"
27#include "./placeholder.hpp"
28#include "../macros.hpp"
29
30#include <type_traits>
31#include <utility>
32
33namespace nda::clef {
34
51 template <typename T, int... Is>
54 T obj;
55
67 template <typename... Args>
68 FORCEINLINE decltype(auto) operator()(Args &&...args) const {
69 return eval(obj, pair<Is, Args>{std::forward<Args>(args)}...);
70 }
71 };
72
99 template <typename T, typename... Phs>
100 FORCEINLINE auto make_function(T &&obj, Phs...) {
101 return make_fun_impl<std::decay_t<T>, Phs::index...>{std::forward<T>(obj)};
102 }
103
114 template <typename T, int... Is, typename... Pairs>
115 struct evaluator<make_fun_impl<T, Is...>, Pairs...> {
117 using e_t = evaluator<T, Pairs...>;
118
120 static constexpr bool is_lazy = (detail::ph_set<make_fun_impl<T, Is...>>::value != detail::ph_set<Pairs...>::value);
121
133 FORCEINLINE decltype(auto) operator()(make_fun_impl<T, Is...> const &f, Pairs &...pairs) const {
134 return make_function(e_t()(f.obj, pairs...), placeholder<Is>()...);
135 }
136 };
137
138 namespace detail {
139
140 // Specialization of is_function_impl for nda::clef::make_fun_impl types.
141 template <typename Expr, int... Is>
142 inline constexpr bool is_function_impl<make_fun_impl<Expr, Is...>> = true;
143
144 // Specialization of ph_set for nda::clef::make_fun_impl types.
145 template <typename Expr, int... Is>
146 struct ph_set<make_fun_impl<Expr, Is...>> {
147 static constexpr ull_t value = ph_filter<ph_set<Expr>::value, Is...>::value;
148 };
149
150 // Specialization of is_lazy_impl for nda::clef::make_fun_impl types.
151 template <typename Expr, int... Is>
152 constexpr bool is_lazy_impl<make_fun_impl<Expr, Is...>> = (ph_set<make_fun_impl<Expr, Is...>>::value != 0);
153
154 // Specialization of force_copy_in_expr_impl for nda::clef::make_fun_impl types (always true).
155 template <typename Expr, int... Is>
156 constexpr bool force_copy_in_expr_impl<make_fun_impl<Expr, Is...>> = true;
157
158 } // namespace detail
159
160} // namespace nda::clef
Provides some utility functions and type traits for the CLEF library.
Provides functionality to evaluate lazy expressions from the clef library.
__inline__ decltype(auto) eval(T const &obj, Pairs &&...pairs)
Generic function to evaluate expressions and other types.
Definition eval.hpp:197
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition function.hpp:100
Macros used in the nda library.
Provides placeholders for the clef library.
Generic evaluator for types which do not have a specialized evaluator.
Definition eval.hpp:55
static constexpr bool is_lazy
Constexpr variable that is true if the type T is lazy.
Definition eval.hpp:57
Helper struct to simplify calls to nda::clef::eval.
Definition function.hpp:52
T obj
Object to be evaluated.
Definition function.hpp:54
A pair consisting of a placeholder and its assigned value.
A placeholder is an empty struct, labelled by an int.