Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to create a completely arbitrary private member tuple in a C++11 variadic class constructor?
    text
    copied!<p>My apologies if this has been asked before - searched with no definite answer, and I'm beginning to wonder if it is even possible. I am trying to learn C++11 and have run into trouble with variadic templates. I think I grasp (finally) the concept of variadic function parameters, and why/how recursion is used to unwrap and process them, but am having trouble with a (I think) similar concept in class constructors.</p> <p>Suppose I want to create a variadic template class that has a mixed-type container (assume tuple) as a private member. Is it possible to push an arbitrary number of variously-typed objects into that tuple when the class object is constructed? Something like:</p> <pre><code>#include &lt;tuple&gt; // forward declaration - is this needed? template &lt;class ... args&gt; class myClass; template &lt;class H, class ... T&gt; class myClass &lt;H, T ...&gt; { private: std::tuple&lt;anything can go here&gt; mycontainer; public: myClass(const H&amp; head, const T&amp; ... tail) { push head into mycontainer; do some sort of recursion with tail; } } </code></pre> <p>I've been screwing around with std::tuple_cat and std::make_tuple and thought that I was on to something for a while, but no luck.</p> <p>It has been a long time since I've had anything to do with C++, so my apologies if I'm totally off my nut. I just started looking at this after doing some reading about the C++11 features.</p> <p>EDIT: Just adding that I'm on GCC 4.8.x and/or Visual Studio 2012</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload