Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Type alias for template member function

18 views
Skip to first unread message

Alvin

unread,
Apr 23, 2017, 3:52:00 PM4/23/17
to
Is there a way to write this more elegantly, introducing an alias for
"std::tuple_element<type_nr, tuple_t>::type"?



#include <tuple>

template<typename... types>
struct S {
using tuple_t = std::tuple<types...>;

template<size_t type_nr>
void f(typename std::tuple_element<type_nr, tuple_t>::type v1,
typename std::tuple_element<type_nr, tuple_t>::type v2,
typename std::tuple_element<type_nr, tuple_t>::type v3,
typename std::tuple_element<type_nr, tuple_t>::type v4) { }
};

Alf P. Steinbach

unread,
Apr 23, 2017, 4:41:18 PM4/23/17
to
One possibility:


template< class... Types >
struct S {
template< int i >
using Arg = std::tuple_element_t<i, std::tuple<Types...>>;

template< int i >
void f( Arg<i> v1, Arg<i> v2, Arg<i> v3, Arg<i> v4 ) {}
};


Cheers & hth.,

- Alf

Alvin

unread,
Apr 23, 2017, 5:08:12 PM4/23/17
to
That is better.

Thanks!
0 new messages