Forwarding variadic arguments in std::enable_if via other function

Viewed 81

Following issue:

#include <iostream>
#include <array>
#include <type_traits>

    using namespace std;

    template <typename... Args>
    inline constexpr size_t variadicElementCounter(Args... args)
    {
        return sizeof...(args); // get num of arguments in the parameter pack
    }

    template <typename DataType, size_t SizeValue>
    class Sth
    {
    public:
         Sth()=default;
         ~Sth()=default;

        template<typename ... VariadicValues, std::enable_if_t<(variadicElementCounter(VariadicValues...)) == SizeValue> * = nullptr>
        Sth(VariadicValues && ... f_values) noexcept : m_arr{ std::move(f_values) ...}
        {

        }

    private:
        std::array<DataType,SizeValue> m_arr;
     };

int main()
{
   // arr= {1,2,3};
    Sth<int,3> something={1,2,3};

    cout<<"Hello World";

    return 0;
}

The example can be executed here: https://onlinegdb.com/r1Qpj67BI

Trying to compile this class, the VariadicValues... (probably) breaks the compilation What am I doing wrong (because I want to avoid calling sizeof...(VariadicValues) in the enable_if expression

0 Answers
Related