It changes the way it interacts with std::is_constructible and std::is_convertible with optional . For example:
class A {}; int main() { std::cout << std::is_constructible<optional<A>, int>::value << '\n'; };
Your source code will be printed:
0
But your new code will be printed:
1
If this is undesirable, and you still want to upgrade with the new code, you can enable_if limit it to U valid types.
The only other possible problem that I see is that T may be a reference type (e.g. int& ). In this case, the second constructor of the source code looks suspicious, because it will pass the value of r, and you can try to associate this value with a reference to the constant lvalue (you canβt say for sure). If T never be a reference type, no need to worry about that.
Howard hinnant
source share