Template argument output for constructors

Does C ++ 0x (or was C ++ 0x at some point in time) have a template argument output for constructors? In the Coming C ++ Overview (C ++ 0x) Standard, I saw the following lines:

std::lock_guard l(m); // at 7:00 std::thread t(f); // at 9:00 

Does this mean that delegating make_foo function make_foo completely redundant?

+7
source share
1 answer

The output of the template argument works for any function, including the constructor. But you cannot infer class template parameters from the arguments passed to the constructor. And no, you cannot do this in C ++ 0x.

 struct X { template <class T> X(T x) {} }; template <class T> struct Y { Y(T y) {} }; int main() { X x(3); //T is deduced to be int. OK in C++03 and C++0x; Y y(3); //compiler error: missing template argument list. Error in 03 and 0x } 

lock_guard and thread are not class templates. However, they do have constructor templates.

+14
source

All Articles