tuple: add `index' type query for tuple types
util::tuple::index finds the first occurence of a type in a tuple and gives the index of this type.
This commit is contained in:
parent
af3dcbb418
commit
b9ca3f6969
26
tuple.hpp
26
tuple.hpp
@ -185,7 +185,31 @@ namespace util::tuple {
|
|||||||
{
|
{
|
||||||
ignore (std::forward<Args> (args)...);
|
ignore (std::forward<Args> (args)...);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
/// query the index of the first occurrence of type `T' in the tuple type
|
||||||
|
/// `TupleT'.
|
||||||
|
///
|
||||||
|
/// if the query type does not occur in the tuple type a compiler error
|
||||||
|
/// should be generated.
|
||||||
|
template <class T, class TupleT>
|
||||||
|
struct index;
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <class T, class ...Types>
|
||||||
|
struct index<T, std::tuple<T, Types...>> {
|
||||||
|
static constexpr std::size_t value = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <class T, class U, class ...Types>
|
||||||
|
struct index<T,std::tuple<U, Types...>> {
|
||||||
|
static constexpr std::size_t value = 1 + index<T, std::tuple<Types...>>::value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user