OpenLB 1.7
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
olb::meta Namespace Reference

Classes

struct  derived_type_in_nested
 
struct  eq
 Evaluates to true iff T is in TYPES. More...
 
struct  filter
 Return type list of all FIELDS meeting COND. More...
 
struct  filter< COND, TYPE >
 Return either nil type list or type list containing (single) FIELD depending on COND. More...
 
struct  first_type_with_base
 Get first type based on BASE contained in a given type list. More...
 
struct  first_type_with_base< BASE, HEAD >
 
struct  id
 Identity type to pass non-constructible types as value. More...
 
struct  index_of_first_matching
 Helper for computing indices in type lists. More...
 
struct  index_of_first_matching< COND >
 
struct  index_of_first_matching< COND, HEAD, TAIL... >
 
struct  list
 Plain wrapper for list of types. More...
 
struct  list_base
 Base of any meta::list. More...
 
struct  list_item_with_base_default_base
 Get first type based on BASE contained in a given type list. More...
 
struct  list_item_with_base_default_base< BASE, HEAD >
 
struct  neq
 Evaluates to true iff T is not in TYPES. More...
 
struct  plain_map
 
struct  reverse
 Return type list of all FIELDS in reversed order. More...
 
struct  reverse< TYPE >
 Return either nil type list or type list containing FIELD in reversed order. More...
 
struct  unzip_flattened_keys
 
struct  unzip_flattened_keys< KEY, VALUE, TAIL... >
 
struct  unzip_flattened_keys<>
 
struct  unzip_flattened_values
 
struct  unzip_flattened_values< KEY, VALUE, TAIL... >
 
struct  unzip_flattened_values<>
 

Typedefs

template<typename TYPE >
using id_t = typename id<TYPE>::type
 
template<auto VALUE, typename TYPE = decltype(VALUE)>
using value = typename std::integral_constant<TYPE, VALUE>::type
 Identity type to wrap non-type template arguments.
 
template<typename T >
using is_arithmetic
 Checks whether T can be used as a scalar arithmetic type.
 
template<typename T , typename U = void>
using enable_if_arithmetic_t = std::enable_if_t<is_arithmetic<T>::type::value, U>
 
template<typename BASE , typename... TYPES>
using first_type_with_base_t = typename first_type_with_base<BASE, TYPES...>::type
 
template<template< typename > class COND, typename... TYPES>
using filter_t = typename filter<COND,TYPES...>::type
 meta::list of TYPES meeting COND
 
template<typename... TYPES>
using reverse_t = typename reverse<TYPES...>::type
 meta::list of TYPES in reversed order
 
template<typename... KVs>
using map
 Map of types.
 

Functions

template<typename TYPE >
bool is_aligned (const void *ptr)
 Returns true iff address ptr is aligned w.r.t. TYPE.
 
template<typename T >
std::string name ()
 Returns distinct name on GCC, Clang and ICC but may return arbitrary garbage as per the standard.
 
template<typename WANTED , typename... TYPES>
constexpr bool contains ()
 Returns true iff a given type list contains WANTED.
 
template<typename... TYPES>
bool contains (std::type_index field)
 Returns true iff a given type list contains a type index.
 
template<typename TYPES , typename F , std::size_t... INDICES>
void list_for_each_index (F &&f, std::index_sequence< INDICES... >)
 Apply F to each element of meta::list listed in INDICES.
 
template<typename TUPLE , typename F , std::size_t... INDICES>
void tuple_for_each_index (TUPLE &tuple, F &&f, std::index_sequence< INDICES... >)
 Apply F to each element of TUPLE listed in INDICES.
 
template<typename TUPLE , typename F >
void tuple_for_each (TUPLE &tuple, F &&f)
 Apply F to each element of TUPLE.
 
template<typename T , unsigned D, typename U , std::size_t... INDICES>
std::array< T, D > make_array (U &&u, std::index_sequence< INDICES... >)
 Return std::array<T,D> where T is initialized with a common value (helper)
 
template<typename T , unsigned D, typename U >
std::array< T, D > make_array (U &&u)
 Return std::array<T,D> where T is initialized with a common value.
 
template<typename T , unsigned D, typename F , std::size_t... INDICES>
std::array< T, D > make_array_f (F &&f, std::index_sequence< INDICES... >)
 Return std::array<T,D> where T is initialized using a iDim-dependent function (helper)
 
template<typename T , unsigned D, typename F >
std::array< T, D > make_array_f (F &&f)
 Return std::array<T,D> where T is initialized using a iDim-dependent function.
 
template<auto... VALUE, typename COND >
constexpr bool indexed_pack_contains (COND cond)
 Returns true iff at least one VALUE satisfies COND.
 
template<std::size_t... Is, std::size_t... Js>
constexpr auto operator+ (std::index_sequence< Is... >, std::index_sequence< Js... >)
 Concatenate two index sequences.
 
template<std::size_t... Is>
constexpr auto array_from_index_sequence (std::index_sequence< Is... >)
 Convert index sequence into an array of its values.
 
template<typename PREDICATE , std::size_t... Is>
constexpr auto filter_index_sequence (PREDICATE predicate, std::index_sequence< Is... >)
 Return index sequence of Is matching PREDICATE depending on index.
 
template<typename TYPES , typename PREDICATE , std::size_t... Is>
constexpr auto filter_index_sequence (PREDICATE predicate, std::index_sequence< Is... >)
 Return index sequence of Is matching PREDICATE depending on type in TYPES.
 
template<typename TYPES , template< typename > class COND, std::size_t... Is>
constexpr auto filter_index_sequence (std::index_sequence< Is... >)
 Return index sequence of Is matching COND in TYPES.
 
template<typename TYPES , template< typename > class COND>
constexpr auto filter_index_sequence ()
 Return index sequence of Is matching COND using index_sequence of TYPES.
 
template<typename MAP , std::size_t... Is>
constexpr auto map_index_sequence (MAP map, std::index_sequence< Is... >)
 
template<std::size_t N, std::size_t I, std::size_t... Is>
constexpr auto take_n_sequence (std::index_sequence< I, Is... >)
 
template<std::size_t N, std::size_t I, std::size_t... Is>
constexpr auto drop_n_sequence (std::index_sequence< I, Is... >)
 
template<std::size_t N>
constexpr auto zero_sequence ()
 
template<std::size_t I, std::size_t O>
constexpr auto make_index_sequence_in_range ()
 
template<std::size_t... Is>
constexpr bool is_zero_sequence (std::index_sequence< Is... >)
 
template<typename F , std::size_t... INDICES>
void call_n_times (F &&f, std::index_sequence< INDICES... >)
 Call F for each index (exlicitly unrolled loop)
 
template<unsigned N, typename F >
void call_n_times (F &&f)
 Call F for each i in 0..N-1 (exlicitly unrolled loop)
 
template<typename TYPES , typename Fa , typename Fb , std::size_t Ia, std::size_t Iaa, std::size_t... Is>
void index_sequence_for_subsequence_L2 (Fa &&fa, Fb &&fb, std::index_sequence< Ia, Iaa, Is... > seq)
 Call fa for indices in index_sequence and call fb for indices in between indices in.
 
template<typename TYPES , typename Fa , typename Fb , std::size_t I, std::size_t... Is>
void index_sequence_for_subsequence_L1 (Fa &&fa, Fb &&fb, std::index_sequence< I, Is... > seq)
 Call fa for indices in index_sequence and call fb for indices in between indices in.
 
template<typename TYPES , typename Fa , typename Fb , std::size_t... Is>
void index_sequence_for_subsequence (Fa &&fa, Fb &&fb, std::index_sequence< Is... > seq)
 Call fa for indices in index_sequence and call fb for indices in between indices in.
 

Typedef Documentation

◆ enable_if_arithmetic_t

template<typename T , typename U = void>
using olb::meta::enable_if_arithmetic_t = std::enable_if_t<is_arithmetic<T>::type::value, U>

Definition at line 121 of file meta.h.

◆ filter_t

template<template< typename > class COND, typename... TYPES>
using olb::meta::filter_t = typename filter<COND,TYPES...>::type

meta::list of TYPES meeting COND

Definition at line 245 of file meta.h.

◆ first_type_with_base_t

template<typename BASE , typename... TYPES>
using olb::meta::first_type_with_base_t = typename first_type_with_base<BASE, TYPES...>::type

Definition at line 189 of file meta.h.

◆ id_t

template<typename TYPE >
using olb::meta::id_t = typename id<TYPE>::type

Definition at line 92 of file meta.h.

◆ is_arithmetic

template<typename T >
using olb::meta::is_arithmetic
Initial value:
typename std::integral_constant<bool,
std::is_base_of_v<AD,T>
|| std::is_base_of_v<SimdBase,T>
|| std::is_base_of_v<ExprBase,T>
|| std::is_arithmetic_v<T>
|| std::is_pointer_v<T>
|| std::is_enum_v<T>
>

Checks whether T can be used as a scalar arithmetic type.

Base checking for AD types to be replaced by e.g. concepts in C++20

Definition at line 109 of file meta.h.

◆ map

template<typename... KVs>
using olb::meta::map
Initial value:
plain_map<
typename unzip_flattened_keys<KVs...>::type,
typename unzip_flattened_values<KVs...>::type
>

Map of types.

Definition at line 88 of file typeMap.h.

◆ reverse_t

template<typename... TYPES>
using olb::meta::reverse_t = typename reverse<TYPES...>::type

meta::list of TYPES in reversed order

Definition at line 269 of file meta.h.

◆ value

template<auto VALUE, typename TYPE = decltype(VALUE)>
using olb::meta::value = typename std::integral_constant<TYPE, VALUE>::type

Identity type to wrap non-type template arguments.

Definition at line 96 of file meta.h.

Function Documentation

◆ array_from_index_sequence()

template<std::size_t... Is>
constexpr auto olb::meta::array_from_index_sequence ( std::index_sequence< Is... > )
constexpr

Convert index sequence into an array of its values.

Definition at line 422 of file meta.h.

423{
424 return std::array<std::size_t,sizeof...(Is)>{Is...};
425}
+ Here is the caller graph for this function:

◆ call_n_times() [1/2]

template<unsigned N, typename F >
void olb::meta::call_n_times ( F && f)

Call F for each i in 0..N-1 (exlicitly unrolled loop)

Definition at line 521 of file meta.h.

521 {
522 return call_n_times<F>(std::forward<F&&>(f), std::make_index_sequence<N>{});
523}

◆ call_n_times() [2/2]

template<typename F , std::size_t... INDICES>
void olb::meta::call_n_times ( F && f,
std::index_sequence< INDICES... >  )

Call F for each index (exlicitly unrolled loop)

Definition at line 515 of file meta.h.

515 {
516 (f(INDICES), ...);
517}

◆ contains() [1/2]

template<typename WANTED , typename... TYPES>
constexpr bool olb::meta::contains ( )
constexpr

Returns true iff a given type list contains WANTED.

Definition at line 125 of file meta.h.

125 {
126 return (std::is_same_v<WANTED, TYPES> || ... || false);
127}
+ Here is the caller graph for this function:

◆ contains() [2/2]

template<typename... TYPES>
bool olb::meta::contains ( std::type_index field)

Returns true iff a given type list contains a type index.

Definition at line 131 of file meta.h.

131 {
132 return ((field == typeid(TYPES)) || ... || false);
133}

◆ drop_n_sequence()

template<std::size_t N, std::size_t I, std::size_t... Is>
constexpr auto olb::meta::drop_n_sequence ( std::index_sequence< I, Is... > )
constexpr

Definition at line 485 of file meta.h.

485 {
486 if constexpr (N > 0) {
487 return drop_n_sequence<N-1>(std::index_sequence<Is...>());
488 } else {
489 return std::index_sequence<I,Is...>();
490 }
491 __builtin_unreachable();
492}
constexpr auto drop_n_sequence(std::index_sequence< I, Is... >)
Definition meta.h:485

References drop_n_sequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filter_index_sequence() [1/4]

template<typename TYPES , template< typename > class COND>
constexpr auto olb::meta::filter_index_sequence ( )
constexpr

Return index sequence of Is matching COND using index_sequence of TYPES.

Definition at line 465 of file meta.h.

465 {
466 return filter_index_sequence<TYPES,COND>(std::make_index_sequence<TYPES::size>());
467}
+ Here is the caller graph for this function:

◆ filter_index_sequence() [2/4]

template<typename PREDICATE , std::size_t... Is>
constexpr auto olb::meta::filter_index_sequence ( PREDICATE predicate,
std::index_sequence< Is... >  )
constexpr

Return index sequence of Is matching PREDICATE depending on index.

Definition at line 429 of file meta.h.

429 {
430 return (
431 std::conditional_t<predicate(Is),
432 std::index_sequence<Is>,
433 std::index_sequence<>>()
434 + ...
435 + std::index_sequence<>()
436 );
437}

◆ filter_index_sequence() [3/4]

template<typename TYPES , typename PREDICATE , std::size_t... Is>
constexpr auto olb::meta::filter_index_sequence ( PREDICATE predicate,
std::index_sequence< Is... >  )
constexpr

Return index sequence of Is matching PREDICATE depending on type in TYPES.

Definition at line 441 of file meta.h.

441 {
442 return (
443 std::conditional_t<predicate(id<typename TYPES::template get<Is>>()),
444 std::index_sequence<Is>,
445 std::index_sequence<>>()
446 + ...
447 + std::index_sequence<>()
448 );
449}

◆ filter_index_sequence() [4/4]

template<typename TYPES , template< typename > class COND, std::size_t... Is>
constexpr auto olb::meta::filter_index_sequence ( std::index_sequence< Is... > )
constexpr

Return index sequence of Is matching COND in TYPES.

Definition at line 453 of file meta.h.

453 {
454 return (
455 std::conditional_t<COND<typename TYPES::template get<Is>>::value,
456 std::index_sequence<Is>,
457 std::index_sequence<>>()
458 + ...
459 + std::index_sequence<>()
460 );
461}

◆ index_sequence_for_subsequence()

template<typename TYPES , typename Fa , typename Fb , std::size_t... Is>
void olb::meta::index_sequence_for_subsequence ( Fa && fa,
Fb && fb,
std::index_sequence< Is... > seq )

Call fa for indices in index_sequence and call fb for indices in between indices in.

Definition at line 559 of file meta.h.

559 {
560 if constexpr (seq.size()>0) {
561 index_sequence_for_subsequence_L1<TYPES>(fa, fb, seq );
562 } else {
563 fb(std::make_index_sequence<TYPES::size>());
564 }
565}

◆ index_sequence_for_subsequence_L1()

template<typename TYPES , typename Fa , typename Fb , std::size_t I, std::size_t... Is>
void olb::meta::index_sequence_for_subsequence_L1 ( Fa && fa,
Fb && fb,
std::index_sequence< I, Is... > seq )

Call fa for indices in index_sequence and call fb for indices in between indices in.

Definition at line 546 of file meta.h.

546 {
547 fb(std::make_index_sequence<I>());
548 if constexpr (seq.size()>1) {
549 index_sequence_for_subsequence_L2<TYPES>(fa, fb, seq );
550 } else {
551 fa(id<typename TYPES::template get<I>>());
552 fb(make_index_sequence_in_range<I+1,TYPES::size>());
553 }
554}

◆ index_sequence_for_subsequence_L2()

template<typename TYPES , typename Fa , typename Fb , std::size_t Ia, std::size_t Iaa, std::size_t... Is>
void olb::meta::index_sequence_for_subsequence_L2 ( Fa && fa,
Fb && fb,
std::index_sequence< Ia, Iaa, Is... > seq )

Call fa for indices in index_sequence and call fb for indices in between indices in.

Definition at line 530 of file meta.h.

530 {
531 if constexpr (seq.size()>2) {
532 fa(id<typename TYPES::template get<Ia>>());
533 fb(make_index_sequence_in_range<Ia+1,Iaa>());
534 index_sequence_for_subsequence_L2<TYPES>(fa,fb,std::index_sequence<Iaa,Is...>());
535 } else {
536 fa(id<typename TYPES::template get<Ia>>());
537 fb(make_index_sequence_in_range<Ia+1,Iaa>());
538 fa(id<typename TYPES::template get<Iaa>>());
539 fb(make_index_sequence_in_range<Iaa+1,TYPES::size>());
540 }
541}

◆ indexed_pack_contains()

template<auto... VALUE, typename COND >
constexpr bool olb::meta::indexed_pack_contains ( COND cond)
constexpr

Returns true iff at least one VALUE satisfies COND.

Definition at line 404 of file meta.h.

404 {
405 std::size_t i = 0;
406 return (cond(i++, VALUE) || ...);
407}
+ Here is the caller graph for this function:

◆ is_aligned()

template<typename TYPE >
bool olb::meta::is_aligned ( const void * ptr)

Returns true iff address ptr is aligned w.r.t. TYPE.

Definition at line 69 of file meta.h.

69 {
70 auto addr = reinterpret_cast<std::uintptr_t>(ptr);
71 return !(addr % alignof(TYPE));
72}

◆ is_zero_sequence()

template<std::size_t... Is>
constexpr bool olb::meta::is_zero_sequence ( std::index_sequence< Is... > )
constexpr

Definition at line 509 of file meta.h.

509 {
510 return ((Is == 0) && ... && true);
511}

◆ list_for_each_index()

template<typename TYPES , typename F , std::size_t... INDICES>
void olb::meta::list_for_each_index ( F && f,
std::index_sequence< INDICES... >  )

Apply F to each element of meta::list listed in INDICES.

Definition at line 344 of file meta.h.

345{
346 if constexpr (std::is_invocable_v<F, decltype(id<typename TYPES::template get<0>>()), unsigned>) {
347 (f(id<typename TYPES::template get<INDICES>>(), INDICES), ...);
348 } else {
349 (f(id<typename TYPES::template get<INDICES>>()), ...);
350 }
351}
Identity type to pass non-constructible types as value.
Definition meta.h:79

◆ make_array() [1/2]

template<typename T , unsigned D, typename U >
std::array< T, D > olb::meta::make_array ( U && u)

Return std::array<T,D> where T is initialized with a common value.

Definition at line 383 of file meta.h.

384{
385 return make_array<T,D,U>(std::forward<U>(u), std::make_index_sequence<D> {});
386}

◆ make_array() [2/2]

template<typename T , unsigned D, typename U , std::size_t... INDICES>
std::array< T, D > olb::meta::make_array ( U && u,
std::index_sequence< INDICES... >  )

Return std::array<T,D> where T is initialized with a common value (helper)

Definition at line 376 of file meta.h.

377{
378 return std::array<T,D> {(INDICES, u)...};
379}

◆ make_array_f() [1/2]

template<typename T , unsigned D, typename F >
std::array< T, D > olb::meta::make_array_f ( F && f)

Return std::array<T,D> where T is initialized using a iDim-dependent function.

Definition at line 397 of file meta.h.

398{
399 return make_array_f<T,D,F>(std::forward<F&&>(f), std::make_index_sequence<D> {});
400}

◆ make_array_f() [2/2]

template<typename T , unsigned D, typename F , std::size_t... INDICES>
std::array< T, D > olb::meta::make_array_f ( F && f,
std::index_sequence< INDICES... >  )

Return std::array<T,D> where T is initialized using a iDim-dependent function (helper)

Definition at line 390 of file meta.h.

391{
392 return std::array<T,D> {f(INDICES)...};
393}

◆ make_index_sequence_in_range()

template<std::size_t I, std::size_t O>
constexpr auto olb::meta::make_index_sequence_in_range ( )
constexpr

Definition at line 502 of file meta.h.

502 {
503 return map_index_sequence([](std::size_t Is) constexpr {
504 return (Is+I);
505 }, std::make_index_sequence<(O-I)>());
506}
constexpr auto map_index_sequence(MAP map, std::index_sequence< Is... >)
Definition meta.h:470

References map_index_sequence().

+ Here is the call graph for this function:

◆ map_index_sequence()

template<typename MAP , std::size_t... Is>
constexpr auto olb::meta::map_index_sequence ( MAP map,
std::index_sequence< Is... >  )
constexpr

Definition at line 470 of file meta.h.

470 {
471 return std::index_sequence<map(Is)...>();
472}
+ Here is the caller graph for this function:

◆ name()

template<typename T >
std::string olb::meta::name ( )

Returns distinct name on GCC, Clang and ICC but may return arbitrary garbage as per the standard.

Definition at line 100 of file meta.h.

100 {
101 return typeid(T).name();
102}
std::string name()
Returns distinct name on GCC, Clang and ICC but may return arbitrary garbage as per the standard.
Definition meta.h:100

References name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator+()

template<std::size_t... Is, std::size_t... Js>
constexpr auto olb::meta::operator+ ( std::index_sequence< Is... > ,
std::index_sequence< Js... >  )
constexpr

Concatenate two index sequences.

Definition at line 413 of file meta.h.

414{
415 return std::index_sequence<Is..., Js...>();
416}

◆ take_n_sequence()

template<std::size_t N, std::size_t I, std::size_t... Is>
constexpr auto olb::meta::take_n_sequence ( std::index_sequence< I, Is... > )
constexpr

Definition at line 475 of file meta.h.

475 {
476 if constexpr (N > 0) {
477 return std::index_sequence<I>() + take_n_sequence<N-1>(std::index_sequence<Is...>());
478 } else {
479 return std::index_sequence<>();
480 }
481 __builtin_unreachable();
482}
constexpr auto take_n_sequence(std::index_sequence< I, Is... >)
Definition meta.h:475

References take_n_sequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuple_for_each()

template<typename TUPLE , typename F >
void olb::meta::tuple_for_each ( TUPLE & tuple,
F && f )

Apply F to each element of TUPLE.

Definition at line 369 of file meta.h.

370{
371 tuple_for_each_index(tuple, std::forward<F>(f), std::make_index_sequence<std::tuple_size<TUPLE>::value> {});
372}
void tuple_for_each_index(TUPLE &tuple, F &&f, std::index_sequence< INDICES... >)
Apply F to each element of TUPLE listed in INDICES.
Definition meta.h:355

References tuple_for_each_index().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuple_for_each_index()

template<typename TUPLE , typename F , std::size_t... INDICES>
void olb::meta::tuple_for_each_index ( TUPLE & tuple,
F && f,
std::index_sequence< INDICES... >  )

Apply F to each element of TUPLE listed in INDICES.

Definition at line 355 of file meta.h.

356{
357 if constexpr (std::is_invocable_v<F, decltype(std::get<0>(tuple)), std::integral_constant<std::size_t,0>>) {
358 (f(std::get<INDICES>(tuple), std::integral_constant<std::size_t,INDICES>{}), ...);
359 } else if constexpr (std::is_invocable_v<F, decltype(std::get<0>(tuple)), unsigned>) {
360 (f(std::get<INDICES>(tuple), INDICES), ...);
361 } else {
362 (f(std::get<INDICES>(tuple)), ...);
363 }
364}
+ Here is the caller graph for this function:

◆ zero_sequence()

template<std::size_t N>
constexpr auto olb::meta::zero_sequence ( )
constexpr

Definition at line 495 of file meta.h.

495 {
496 return map_index_sequence([](std::size_t) constexpr {
497 return 0;
498 }, std::make_index_sequence<N>());
499}

References map_index_sequence().

+ Here is the call graph for this function: