0

This website teach us how to implement a simple std::tuple, but there are a piece of codes I do not understand

template <size_t k, class... Ts> typename std::enable_if< k == 0, typename elem_type_holder<0, tuple<Ts...>>::type&>::type get(tuple<Ts...>& t) { return t.tail; } template <size_t k, class T, class... Ts> typename std::enable_if< k != 0, typename elem_type_holder<k, tuple<T, Ts...>>::type&>::type get(tuple<T, Ts...>& t) { //Why t could assign to different type? tuple<Ts...>& base = t; return get<k - 1>(base); } 

My question is

tuple<T, Ts...> 

and

tuple<Ts...> 

are different types, how could it work?

Edit : I think I found the answer, because

tuple<Ts...> 

is base class of

tuple<T,Ts...> 
4
  • Do you know how inheritance works? Commented Jan 6, 2018 at 14:43
  • In the second case Ts... type list can consist of T, Ts... so they can be the same type. Commented Jan 6, 2018 at 14:43
  • @VTT No, that would make Ts... an infinite list. Commented Jan 6, 2018 at 14:44
  • @meplomene yes, I know, my unfamiliar with variadic template blind my eye at first Commented Jan 6, 2018 at 14:48

1 Answer 1

1

Probably tuple<T, Ts...> inherits from tuple<Ts...>.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.