Search code examples
c++variadic-functionsparameter-pack

Is there a way to get the values in a parameter pack without using recursion?


I've seen many example codes that use recursion to extract the values from a parameter pack. Is there any way, other than recursion, to extract the values from a parameter pack?


Solution

  • Depending on what you want to do, you can use C++17 fold expressions:

    template <int ... ints>
    constexpr int product() {
        return (ints * ...);
    }