1 #ifndef _TUPLECLASS_HPP 2 #define _TUPLECLASS_HPP 10 #include <ints/IntSeq.hpp> 11 #include <metaprogramming/TypeTraits.hpp> 36 struct _isTuple<Tuple<Tp...>> :
public TrueType
46 _isTuple<Unqualified<T>>::value;
49 #define STATIC_ASSERT_IS_TUPLE(T) 50 static_assert(isTuple<T>,"Type is not a tuple") 64 typename=EnableIf<isTuple<Tp>>>
65 using TupleElementType=
66 typename std::tuple_element<I,Tp>::type;
74 std::tuple_size<Unqualified<T>>::value;
94 #define DEFINE_VARIADIC_TYPE_FROM_TUPLE(TYPE) 101 struct _ ## TYPE ## FromTuple; 106 template <class...Tp> 107 struct _ ## TYPE ## FromTuple<Tuple<Tp...>> 111 using type=TYPE<Tp...>; 118 class=ConstrainIsTuple<TP>> 119 using TYPE ## FromTuple=typename _ ## TYPE ## FromTuple<TP>::type 130 static constexpr
int _nOfTypeInTuple=
138 static constexpr
int _nOfTypeInTuple<T,Tuple<Tp...>> =
139 hSum<isSame<T,Tp>...>;
146 class=ConstrainIsTuple<TP>>
148 static constexpr
int nOfTypeInTuple=
149 _nOfTypeInTuple<T,TP>;
157 class=ConstrainIsTuple<T>>
159 static constexpr
int nDiffTypesInTuple=
165 template <
class...Tp>
166 static constexpr
int nDiffTypesInTuple<Tuple<Tp...>> =
167 IntSeq<(nOfTypeInTuple<Tp,Tuple<Tp...>> ==1)...>::hSum;
173 class=ConstrainIsTuple<T>>
175 static constexpr
bool tupleTypesAreAllDifferent=
176 (nDiffTypesInTuple<T> ==tupleSize<T>);
179 #define STATIC_ASSERT_TUPLE_TYPES_ARE_ALL_DIFFERENT(T) 180 static_assert(tupleTypesAreAllDifferent<T>,"Types in the tuple are not all different") 194 template <
typename T,
196 constexpr
bool _tupleHasType(T,
199 return (isSame<T,Tp> || ...);
203 template <
typename T,
205 typename=ConstrainIsTuple<Tp>>
207 constexpr
bool tupleHasType=
208 _tupleHasType(T{},Tp{});
211 #define STATIC_ASSERT_TUPLE_HAS_TYPE(T, 213 static_assert(tupleHasType<T,TP>,"Searched type not found") 225 #define STATIC_ASSERT_TUPLE_HAS_NOT_TYPE(T,TP) 226 static_assert(not tupleHasType<T,TP>,"Searched type found") 242 template <
typename...ToBeSearchedTypes,
243 typename...ContainingTypes>
244 constexpr
bool _tupleHasTypes(Tuple<ToBeSearchedTypes...>,
245 Tuple<ContainingTypes...>)
247 return (tupleHasType<ToBeSearchedTypes,Tuple<ContainingTypes...>> && ...);
253 template <
typename TpToSearch,
254 typename TpContaining>
256 constexpr
bool tupleHasTypes=
257 _tupleHasTypes(TpToSearch{},TpContaining{});
#define STATIC_ASSERT_TUPLE_HAS_TYPE(T,TP)
Assert if the type T is not in the types of tuple TP.
Constrain all types in the tuple to be different.
Constrain a type T to be not contained in a Tuple.
#define STATIC_ASSERT_TUPLE_TYPES_ARE_ALL_DIFFERENT(T)
Assert if the Tuple contains multiple times a given type.
#define STATIC_ASSERT_IS_TUPLE(T)
Assert if the type is not a Tuple.
Constrain the class T to be a Tuple.
#define STATIC_ASSERT_TUPLE_HAS_NOT_TYPE(T, TP)
Assert if the type T is in the types of tuple TP.
constexpr int tupleSize
Total number of elements in a Tuple.
Constrain a type T to be contained in a Tuple.