1#ifndef _BBM_APPLY_ALL_H_
2#define _BBM_APPLY_ALL_H_
17 template<
typename T>
struct get_size {
static constexpr size_t value = 1; };
37 template<
typename FUNC,
typename... T>
requires (
38 !std::is_void_v<
find_first<bbm::detail::has_reflection, T...> > ||
39 !std::is_void_v<
find_first<bbm::detail::is_gettable, T...> > ||
40 requires(
const FUNC& func,
const T&... t) {{func(
value(t)...)};}
42 inline auto apply_all(
const FUNC& func,
const T&... t)
45 auto get_if = []<
size_t IDX>(
auto&& v)
47 using V =
decltype(v);
52 auto reflected_if = [](
auto&& v)
54 using V =
decltype(v);
59 auto call_func = [&]<
size_t IDX>()
61 return apply_all( func, get_if.template
operator()<IDX>(t)... );
64 auto call_func_all = [&]<
size_t... IDX>(std::index_sequence<IDX...>)
66 return std::make_tuple( call_func.template
operator()<IDX>()... );
70 using ReflType =
find_first< bbm::detail::has_reflection, T...>;
71 using GetType =
find_first< bbm::detail::is_gettable, T...>;
82 else if constexpr ( !std::is_void_v<GetType> && ((bbm::detail::get_size<GetType>::value == bbm::detail::get_size<T>::value || !
bbm::concepts::gettable<T>) && ...) )
84 auto result = call_func_all(std::make_index_sequence<bbm::detail::get_size<GetType>::value>{});
89 return std::make_from_tuple<GetType>(result);
96 else return func(
value(t)...);
Helper methods for extracting the value of an attribute (according to concepts::attribute).
constructible_from_tuple concept
Definition: util.h:166
std::get supported
Definition: util.h:175
concept to check if a class supports reflections
Definition: reflection.h:58
constexpr decltype(auto) attributes(T &&t)
Definition: reflection.h:200
typename bbm::reflection::detail::attributes_impl< T >::type attributes_t
Definition: reflection.h:206
Definition: aggregatebsdf.h:29
typename bbm::detail::find_first_impl< TRAIT, void, Ts... >::type find_first
Find first type that matches a type_trait.
Definition: type_traits.h:85
auto apply_all(const FUNC &func, const T &... t)
Apply a function.
Definition: apply_all.h:42
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20
decltype(to_tuple(std::declval< T >())) to_tuple_t
type of converting a type that supports std::get to a tuple
Definition: tuple.h:35
constexpr auto value_copy_tuple(const std::tuple< ARGS... > &tup)
Value-copy a tuple.
Definition: tuple.h:61
A wrapper for STL containers such as tuple, pair, and array. These containers force the programmer to...
Compile-time reflection of:
Additional basic helper concepts.