Why does uniform initialization not work in this case?

50 views Asked by At

Why is it that in this case I cannot use uniform initialization of the member thing from variadic template parameters?

#include <random>
#include <utility>

template <typename T>
class Test
{
public:
    template <typename... Args>
    Test(Args... args)
        : thing { std::forward<Args>(args)... }
    {}
private:
    T thing;
};

int main()
{
    std::mt19937 mt { 42 }; //fine
    Test<std::mt19937> t1 { 42 }; //not fine
}

error: non-constant-expression cannot be narrowed from type 'int' to
'std::mersenne_twister_engine<unsigned long, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7,
2636928640, 15, 4022730752, 18, 1812433253>::result_type' (aka 'unsigned long') in initializer list

https://godbolt.org/z/1n141W

0

There are 0 answers