Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I call a set of variadic base class constructors based on tagged argument packs?
    primarykey
    data
    text
    <p>I'd like to be able to do this:</p> <pre><code>template&lt;typename Mix&gt; struct A { A(int i) { } }; template&lt;typename Mix&gt; struct B { B() { } B(const char*) { } }; template&lt;template&lt;typename&gt; class... Mixins&gt; struct Mix : Mixins&lt;Mix&lt;Mixins...&gt;&gt;... { // This works, but forces constructors to take tuples template&lt;typename... Packs&gt; Mix(Packs... packs) : Packs::Type(packs.constructorArgs)... { } }; template&lt;template&lt;typename&gt; class MixinType, typename... Args&gt; struct ArgPack { typedef MixinType Type; // pretend this is actually a template alias tuple&lt;Args...&gt; constructorArgs; ArgPack(Args... args) : constructorArgs(args...) { } } template&lt;typename... Args&gt; ArgPack&lt;A, Args...&gt; A_(Args... args) { return ArgPack&lt;A, Args...&gt;(args...); } template&lt;typename... Args&gt; ArgPack&lt;B, Args...&gt; B_(Args... args) { return ArgPack&lt;B, Args...&gt;(args...); } Mix&lt;A, B&gt; m(); // error, A has no default constructor Mix&lt;A, B&gt; n(A_(1)); // A(int), B() Mix&lt;A, B&gt; n(A_(1), B_("hello"); // A(int), B(const char*) </code></pre> <p>How do I fill in /* mysterious code here */ to do what I want, to provide a nice interface for calling some set of constructors of mixins? I have a solution that works by making all non-null constructs actually take a tuple of args, and then overloading figures out which one to call, but I would like to avoid constraining mixin authors by making them write a constructor A(tuple), instead of just A(int, int).</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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