c++ - typelist-like (?) template class -


i'm trying achieve following: create template class uses template arguments create instance of template type , use somewhere in the, example constructor. consider following example:

template <typename t> class foo { public:     explicit foo(const t& data) : m_data(data) {}     t m_data; };  template <typename t01, typename t02> class bar { public:     explicit bar(int data) : m_storage(t01(data), t02(data)) {}     void print() { boost::fusion::for_each(m_storage, printer()); }  private:     boost::fusion::vector<t01, t02> m_storage; }; 

and usage:

bar<foo<int>, foo<int>> b(5);     b.print(); 

but if want flexibility in bar class , want number of these t01, t02 classes varying? example:

bar<foo<int>, foo<int>> b(5); b.print(); bar<foo<int>, foo<int>>, foo<int>> c(6); c.print(); 

something using argument pack maybe?

edit001:
final working version on coliru.

you looking variadic template (available since c++11)

template <typename ... ts> class bar { public:     explicit bar(int data) : m_storage(ts(data)...) {}     void print() { boost::fusion::for_each(m_storage, printer()); }  private:     boost::fusion::vector<ts...> m_storage; }; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -