Sorry for the pompous name, I would like to create a constexpr
function, which accepts a variable number of boolean template arguments, and returns the "template index" of the first true
value, in C++11 (C++14 only solutions welcome but won't be accepted as the answer).
For example, calling this function Selector
Selector< false, false >() == 0 // none of the template argument is true
Selector< true, false, true >() == 1 // first true template argument is the first one
Selector< false, false, true, false >() == 3 // .. and here it's the third one
A typical use of this, and the reason why I call it a "type-selector", would be
Selector< std::is_pointer<T>::value, std::is_arithmetic<T>::value >()
and the reason why I'd like it to be a constexpr
is for use in partial template specialisation.
I'm not exactly sure how to go about this, although I think that using variadic templates, constexpr template specialisation (for the 0 case), and recursion (is it possible to "consume" template arguments, like shift
in bash?), this should be doable.
Aucun commentaire:
Enregistrer un commentaire