1

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?

2
  • Which compiler are you using? I tried your code with gcc 4.7.2 and clang 3.3, and both of them produced the expected output. Commented Dec 17, 2012 at 17:29
  • Tried with gcc 4.6.3 and clang 3.0 via <a href="liveworkspace.org/code/35c5Nh$0">liveworkspace</a> and clang 3.0 shows the bug you are observing. Commented Dec 17, 2012 at 17:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm using Apple LLVM 4.1, Good to know it's a compiler problem, I'll update and see if that helps. Also thanks for the sizeof..., I didn't know about that.
There is no version 4.1 of LLVM, presumably you mean Xcode 4.1
@LukeB. By the way, the clang 3.3 was compiled from trunk last night. You'd probably have to search through their bug queue to find out when the behaviour was fixed. I hope that an update helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.