I'm trying to write some kind of preprocessor monstrosity to make simple ctors.
This compiles with g++ -std=c++17
:
template<typename T>
struct foo{
T x;
foo(T _x):x(_x){}
};
auto x=foo(3);
But it would be hard for the monstrosity to know the type of x
, so I tried this:
template<typename T>
struct foo{
T x;
foo(decltype(x) _x):x(_x){}
};
auto x=foo(3);
Which fails (class template argument deduction failed
). But decltype(x)
is just T
anyway, right? So why aren't the code samples equivalent?