Luke B.
Luke B.

Reputation: 1288

Multiple variadic parameters

I'm trying to do something like this:

template <class ... Required>
class Base
{
    template <class First, class ... Rest>
    void bar(First f, Rest ... r)
    {
        [...]
        return bar(r...);
    }
    void bar()
    {
        return;
    }
    public:
        template <class ... Optional>
        void foo(Required ... r, Optional ... o)
        {
            [...]
            bar(r...); //separate the required from the optional
            bar(o...);
        }
};

class Child : Base<Foo1, Foo2>
{
    public:
        Child()
        {
            [...]
            foo(foo1,foo2,foo3);
        }
}

But the first bar call is receiving all the parameters instead of only the Required ones, and the second call is receiving none of the parameters. Did I miss something about multiple variadic parameters? Shouldn't the compiler know that Required... is Foo1,Foo2 and the rest is Optional?

Upvotes: 1

Views: 170

Answers (1)

rici
rici

Reputation: 241671

I think this is most likely a bug in whatever compiler you are using. I tried it with gcc 4.6.3 and 4.7.2, and with clang 3.0 and 3.3, and all of them produced the expected output except clang 3.0.

Upvotes: 1

Related Questions