Wildmeshing Toolkit
Loading...
Searching...
No Matches
get_unique_types.hpp
Go to the documentation of this file.
1
#pragma once
2
#include <tuple>
3
#include <type_traits>
4
#include "
concatenate_types.hpp
"
5
6
namespace
wmtk::utils::metaprogramming::tuple
{
7
8
9
// given a tuple, extracts a tuple with only unique types in the input
10
11
// strategy is to recursively extract the last copy of any given type
12
13
14
// alternates between get_unique_types<tuple<Ts...> with
15
// main_unique_tuple_types<T,std::tuple<Ts...>> to combine Ts... and T,Ts... as necessary
16
17
namespace
detail {
18
19
20
// basic initializations - by default return empty in case the input is empty (which is not caught
21
// by later cases)
22
template
<
typename
...>
23
struct
get_unique_types
24
{
25
using
type
= std::tuple<>;
26
};
27
// basic initialization, expects a T and a Tuple
28
template
<
typename
T,
typename
RemainingTuple>
29
struct
get_unique_types_tuple
30
{
31
};
32
// convenience to avoid typename for get_unique_types...
33
template
<
typename
... Ts>
34
using
get_unique_types_t
=
typename
get_unique_types
<Ts...>::type;
35
36
37
// actual base case - single type is unique so we return that type
38
template
<
typename
T>
39
struct
get_unique_types
<T>
40
{
41
using
type
= std::tuple<T>;
42
};
43
44
45
// from a list of types, check if the first is unique compared to the rest
46
template
<
typename
T,
typename
... Ts>
47
struct
get_unique_types
<T, Ts...>
48
{
49
using
type
=
typename
get_unique_types_tuple
<T, std::tuple<Ts...>>
::type
;
50
};
51
52
53
// do the meat of the implementation - check if T is unique in T,Ts...
54
// if so then add it to the unique of the rest
55
template
<
typename
T,
typename
... Ts>
56
struct
get_unique_types_tuple
<T,
std
::tuple<Ts...>>
57
{
58
// is t unique among T,Ts...
59
constexpr
static
bool
t_is_unique = (!std::is_same_v<T, Ts> && ...);
60
// if its unique then create {T} otherwise {}
61
using
adding_t_type
= std::conditional_t<t_is_unique, std::tuple<T>, std::tuple<>>;
62
63
// concatenate adding_t_type \cup unique(Ts...)
64
using
type
=
concatenate_types_t
<
adding_t_type
,
get_unique_types_t
<Ts...>>;
65
};
66
67
68
}
// namespace detail
69
70
// main access point
71
template
<
typename
... Ts>
72
using
get_unique_types_t
=
detail::get_unique_types_t
<Ts...>;
73
74
}
// namespace wmtk::utils::metaprogramming::tuple
concatenate_types.hpp
std
Definition
autodiff.h:995
wmtk::utils::metaprogramming::tuple::detail::get_unique_types_t
typename get_unique_types< Ts... >::type get_unique_types_t
Definition
get_unique_types.hpp:34
wmtk::utils::metaprogramming::tuple
Definition
as_variant_type.hpp:6
wmtk::utils::metaprogramming::tuple::concatenate_types_t
typename concatenate_types< T, U >::type concatenate_types_t
Definition
concatenate_types.hpp:26
wmtk::utils::metaprogramming::tuple::get_unique_types_t
detail::get_unique_types_t< Ts... > get_unique_types_t
Definition
get_unique_types.hpp:72
wmtk::utils::metaprogramming::tuple::detail::get_unique_types< T, Ts... >::type
typename get_unique_types_tuple< T, std::tuple< Ts... > >::type type
Definition
get_unique_types.hpp:49
wmtk::utils::metaprogramming::tuple::detail::get_unique_types< T >::type
std::tuple< T > type
Definition
get_unique_types.hpp:41
wmtk::utils::metaprogramming::tuple::detail::get_unique_types_tuple< T, std::tuple< Ts... > >::adding_t_type
std::conditional_t< t_is_unique, std::tuple< T >, std::tuple<> > adding_t_type
Definition
get_unique_types.hpp:61
wmtk::utils::metaprogramming::tuple::detail::get_unique_types_tuple< T, std::tuple< Ts... > >::type
concatenate_types_t< adding_t_type, get_unique_types_t< Ts... > > type
Definition
get_unique_types.hpp:64
wmtk::utils::metaprogramming::tuple::detail::get_unique_types_tuple
Definition
get_unique_types.hpp:30
wmtk::utils::metaprogramming::tuple::detail::get_unique_types
Definition
get_unique_types.hpp:24
wmtk::utils::metaprogramming::tuple::detail::get_unique_types::type
std::tuple<> type
Definition
get_unique_types.hpp:25
src
wmtk
utils
metaprogramming
tuple
get_unique_types.hpp
Generated by
1.9.8