Search code examples
c++visual-c++c++17variadic-templates

How to remove elements from variadic template argument?


I'm trying to remove the first element of a variadic template argument. The code goes like this:

template<typename ...T>
auto UniversalHook(T... args)
{
    //I want to remove the first element of `args` here, how can I do that?
    CallToOtherFunction(std::forward<T>(args)...);
}

Solution

  • I just got a little help, and found the solution:

    int main()
    {
        Function(3,5,7);
        return 0;
    }
    template<typename ...T>
    auto CallToAnotherFunction(T&&... args) 
    {
        (cout << ... << args);
    }
    
    template<typename ...T>
    auto Function(T&&... args) {
        /*Return is not needed here*/return [](auto&& /*first*/, auto&&... args_){ 
            return CallToAnotherFunction(std::forward<decltype(args_)>(args_)...); 
        }(std::forward<T>(args)...);
    }
    
    //Output is "57"