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>
5
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
17namespace detail {
18
19
20// basic initializations - by default return empty in case the input is empty (which is not caught
21// by later cases)
22template <typename...>
24{
25 using type = std::tuple<>;
26};
27// basic initialization, expects a T and a Tuple
28template <typename T, typename RemainingTuple>
30{
31};
32// convenience to avoid typename for get_unique_types...
33template <typename... Ts>
34using 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
38template <typename 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
46template <typename T, typename... Ts>
47struct 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
55template <typename T, typename... Ts>
56struct 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...)
65};
66
67
68} // namespace detail
69
70// main access point
71template <typename... Ts>
73
74} // namespace wmtk::utils::metaprogramming::tuple
typename get_unique_types< Ts... >::type get_unique_types_t
typename concatenate_types< T, U >::type concatenate_types_t
detail::get_unique_types_t< Ts... > get_unique_types_t
typename get_unique_types_tuple< T, std::tuple< Ts... > >::type type
std::conditional_t< t_is_unique, std::tuple< T >, std::tuple<> > adding_t_type