TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
function.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
11
12
#pragma once
13
14
#include "
./eval.hpp
"
15
#include "
./utils.hpp
"
16
#include "
./placeholder.hpp
"
17
#include "
../macros.hpp
"
18
19
#include <type_traits>
20
#include <utility>
21
22
namespace
nda::clef {
23
28
40
template
<
typename
T,
int
... Is>
41
struct
make_fun_impl
{
43
T
obj
;
44
56
template
<
typename
... Args>
57
FORCEINLINE
decltype
(
auto
)
operator
()(Args &&...args)
const
{
58
return
eval
(
obj
,
pair<Is, Args>
{std::forward<Args>(args)}...);
59
}
60
};
61
88
template
<
typename
T,
typename
... Phs>
89
FORCEINLINE
auto
make_function
(T &&obj, Phs...) {
90
return
make_fun_impl<std::decay_t<T>
, Phs::index...>{std::forward<T>(obj)};
91
}
92
94
103
template
<
typename
T,
int
... Is,
typename
... Pairs>
104
struct
evaluator
<
make_fun_impl
<T, Is...>, Pairs...> {
106
using
e_t
=
evaluator
<T, Pairs...>;
107
109
static
constexpr
bool
is_lazy
= (detail::ph_set<
make_fun_impl
<T, Is...>>::value != detail::ph_set<Pairs...>::value);
110
122
FORCEINLINE
decltype
(
auto
)
operator
()(
make_fun_impl
<T, Is...>
const
&f, Pairs &...pairs)
const
{
123
return
make_function
(
e_t
()(f.obj, pairs...),
placeholder<Is>
()...);
124
}
125
};
126
127
namespace
detail {
128
129
// Specialization of is_function_impl for nda::clef::make_fun_impl types.
130
template
<
typename
Expr,
int
... Is>
131
inline
constexpr
bool
is_function_impl<make_fun_impl<Expr, Is...>> =
true
;
132
133
// Specialization of ph_set for nda::clef::make_fun_impl types.
134
template
<
typename
Expr,
int
... Is>
135
struct
ph_set<make_fun_impl<Expr, Is...>> {
136
static
constexpr
ull_t value = ph_filter<ph_set<Expr>::value, Is...>::value;
137
};
138
139
// Specialization of is_lazy_impl for nda::clef::make_fun_impl types.
140
template
<
typename
Expr,
int
... Is>
141
constexpr
bool
is_lazy_impl<make_fun_impl<Expr, Is...>> = (ph_set<make_fun_impl<Expr, Is...>>::value != 0);
142
143
// Specialization of force_copy_in_expr_impl for nda::clef::make_fun_impl types (always true).
144
template
<
typename
Expr,
int
... Is>
145
constexpr
bool
force_copy_in_expr_impl<make_fun_impl<Expr, Is...>> =
true
;
146
147
}
// namespace detail
148
149
}
// namespace nda::clef
utils.hpp
Provides some utility functions and type traits for the CLEF library.
eval.hpp
Provides functionality to evaluate lazy expressions from the clef library.
nda::clef::eval
__inline__ decltype(auto) eval(T const &obj, Pairs &&...pairs)
Generic function to evaluate expressions and other types.
Definition
eval.hpp:188
nda::clef::make_function
__inline__ auto make_function(T &&obj, Phs...)
Factory function for nda::clef::make_fun_impl objects.
Definition
function.hpp:89
macros.hpp
Macros used in the nda library.
placeholder.hpp
Provides placeholders for the clef library.
nda::clef::evaluator< make_fun_impl< T, Is... >, Pairs... >::e_t
evaluator< T, Pairs... > e_t
Type of the evaluator used.
Definition
function.hpp:106
nda::clef::evaluator< make_fun_impl< T, Is... >, Pairs... >::is_lazy
static constexpr bool is_lazy
Constexpr variable that is true if all the placeholders are assigned a value.
Definition
function.hpp:109
nda::clef::evaluator
Generic evaluator for types which do not have a specialized evaluator.
Definition
eval.hpp:44
nda::clef::make_fun_impl
Helper struct to simplify calls to nda::clef::eval.
Definition
function.hpp:41
nda::clef::make_fun_impl::obj
T obj
Object to be evaluated.
Definition
function.hpp:43
nda::clef::pair
A pair consisting of a placeholder and its assigned value.
Definition
placeholder.hpp:107
nda::clef::placeholder
A placeholder is an empty struct, labelled by an int.
Definition
placeholder.hpp:51
nda
clef
function.hpp
Generated by
1.17.0