L
lieve again
Hi!
I have read the new C++ standard, C++11, will add to possibility to
use the variadic templates, so a templates can take variable numbers
of template parameters.
Using that the C++ library will add the std::tuple class.
http://en.cppreference.com/w/cpp/utility/tuple
So one can make things like this:
int main()
{
auto t = std::make_tuple(1, "Foo", 3.14);
std::cout << std::get<0>(t)
<< ", " << std::get<1>(t)
<< ", " << std::get<2>(t) << "\n";
}
Output:
1, Foo, 3.14
I'm particularly interested in the implementation of the tuple::get
function. The function prototype looks like:
template< std::size_t I, class... Types >
typename std::tuple_element<I, tuple<Types...> >::type&
get( tuple<Types...>& t );
I understand that the class... Types means any number of arguments,
but I cant realize how can I "get" a particular member of the tuple
class, so for example, the second member.
Anyone knows how can one use the variadic templates?
Thanks,
I have read the new C++ standard, C++11, will add to possibility to
use the variadic templates, so a templates can take variable numbers
of template parameters.
Using that the C++ library will add the std::tuple class.
http://en.cppreference.com/w/cpp/utility/tuple
So one can make things like this:
int main()
{
auto t = std::make_tuple(1, "Foo", 3.14);
std::cout << std::get<0>(t)
<< ", " << std::get<1>(t)
<< ", " << std::get<2>(t) << "\n";
}
Output:
1, Foo, 3.14
I'm particularly interested in the implementation of the tuple::get
function. The function prototype looks like:
template< std::size_t I, class... Types >
typename std::tuple_element<I, tuple<Types...> >::type&
get( tuple<Types...>& t );
I understand that the class... Types means any number of arguments,
but I cant realize how can I "get" a particular member of the tuple
class, so for example, the second member.
Anyone knows how can one use the variadic templates?
Thanks,