How to initialize a tuple with a variadic template parameter?

Hi,

I have this class:

1
2
3
4
5
6
template <typename Target, typename ...RefBy>
struct TableDef
{
	static Target target;
	static std::tuple<RefBy...> reference_list;
};


How do I copy the variadic template RefBy into the tuple reference_list?

Regards,
Juan
Last edited on
Use pack expansion. For example:

1
2
3
4
5
6
7
8
9
10
#include <tuple>

template < typename... TYPES > std::tuple<TYPES...> tup( TYPES&&... refs )
{ return std::tuple<TYPES...>{ std::forward<TYPES>(refs)... } ; } // construct tuple using pack expansion

int main()
{
    const auto tuple = tup( 1, 2.3, "hello", nullptr ) ;
    static_assert( std::tuple_size< decltype(tuple) >::value == 4 ) ;
}

http://coliru.stacked-crooked.com/a/9706b7ffe3d0b24e
But reference_list is static and there is no constructor in the class?? Could you be more specific?

Also, I am already expanding the variadic in reference_list definition is this not enough?
Last edited on
What does this mean? 'copy the variadic template RefBy into the tuple reference_list'
The tuple reference_list is an object, RefBy is a parameter pack of types.
Copy a type to an object? Copy some number of types to an equivalent number of objects?
Let me think and test some things and I will get at you with a more concise question. Thanks for now
Topic archived. No new replies allowed.