TypeForIndex<2, int, double, string>
ok, pattern matching time. First, it clearly matches
template <int current_index, typename... Vs>
struct TypeForIndex {};
therefore no errors. Does this fit any other specialization?
AND:
template <int current_index, typename Head, typename... Tail>
struct TypeForIndex<current_index, Head, Tail...>
AT:
template <int current_index, typename Tail>
struct TypeForIndex<current_index, Tail>
Well, this corresponds to (A), not (B).
(A), current_index - 2, Head - int, Tail... - double, std::string.
template <int current_index, typename Head, typename... Tail>
struct TypeForIndex<current_index, Head, Tail...> : private TypeForIndex<current_index + 1> {
using type = Head;
};
private TypeForIndex<current_index + 1> . , , , . , .
template <int current_index, typename Head, typename... Tail>
struct TypeForIndex<current_index, Head, Tail...> {
using type = Head;
};
, Head int. , type=int.
. type int.
...
, ? (.. , ), , , , . current_index+1 - , , , .
, , :
template <typename Head, typename... Tail>
struct TypeForIndex<0, Head, Tail...> {
using type = Head;
};
template <int current_index, typename Head, typename... Tail>
struct TypeForIndex<current_index, Head, Tail...>:
TypeForIndex<current_index-1, Tail...>
{};
type, .
size_t a int.