Search code examples
c++parametersclangisopack

How to name a single function-parameter-pack?


The question is simple - I wasn't able to find a better example in the ISO C++ documentation then this:

template<class ... targs> void func(targs ... args);

But even for it I wasn't able to find a satisfying explanation. And this is not what I'm looking for as I don't care for the argument types.

I want to write something like this:

void func(auto ... args)
{
    func1(args...); //here 'args' to be expanded
}

But the above or other similar representations won't compile under Clang.

Any ideas why and how can it be done? Also a quote from the latest ISO C++ standard will be welcome too.

What I want to do is implementing 'new' operator behavior by my own function and for this I need to pass constructor arguments with variable size, something like this:

struct x_new
{
    template<class T>
    inline T *allocate(... arg)
    {
        return new T(arg...);
    }
};

Which won't compile under Clang for now and I don't know why.


Solution

  • How about using normal template parameter packs like usual? Like e.g.

    template<typename T, typename... argsT>
    T *allocate(argsT... args)
    {
        return new T(std::forward<argsT>(args)...);
    }