From b9ca3f6969543a380705e9c4e9b7f6ad7adcf5b9 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 11 Jul 2017 11:07:48 +1000 Subject: [PATCH] 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. --- tuple.hpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tuple.hpp b/tuple.hpp index 0f05bca3..cd6260b4 100644 --- a/tuple.hpp +++ b/tuple.hpp @@ -185,7 +185,31 @@ namespace util::tuple { { ignore (std::forward (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 + struct index; + + + //------------------------------------------------------------------------- + template + struct index> { + static constexpr std::size_t value = 0; + }; + + + //------------------------------------------------------------------------- + template + struct index> { + static constexpr std::size_t value = 1 + index>::value; + }; +}; #endif