- Type alias for template member function - 3 Updates
Alvin <Alvin@invalid.invalid>: Apr 23 09:51PM +0200 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" <alf.p.steinbach+usenet@gmail.com>: Apr 23 10:41PM +0200 On 23-Apr-17 9:51 PM, Alvin wrote: > typename std::tuple_element<type_nr, tuple_t>::type v3, > typename std::tuple_element<type_nr, tuple_t>::type v4) { } > }; 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 <Alvin@invalid.invalid>: Apr 23 11:08PM +0200 On 2017-04-23 22:41, Alf P. Steinbach wrote: > template< int i > > void f( Arg<i> v1, Arg<i> v2, Arg<i> v3, Arg<i> v4 ) {} > }; That is better. Thanks! |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment