Talk:cpp/utility/optional/optional
From cppreference.com
template < class U = T > /* EXPLICIT */ constexpr optional( U&& value ); |
(8) | (since C++17) |
This doesn't make sense to me. Should it be template < class T = U >?
gubbins (talk) 02:15, 25 January 2017 (PST)
- T is the template parameter of std::optional. --D41D8CD98F (talk) 02:40, 25 January 2017 (PST)
- We could replace T with value_type (or even with std::optional<T>::value_type), but I guess that wouldn't make it clearer. --D41D8CD98F (talk) 02:42, 25 January 2017 (PST)
- template < class U > would be wrong because it would be a rather different constructor. template <class U = T> EXPLICIT constexpr optional(U&& v); was added to the standard by LWG 2756 which describes its purpose. if you believe it is not useful.. https://isocpp.org/std/submit-issue --Cubbi (talk) 14:00, 25 January 2017 (PST)
- I agree with the remark above. The document you linked does not refer to template <class U = T> in isolation; it is within a declaration of template <class T> optional. So in that setting, the meaning of T is explicit. To readers of this page I do not think it is very clear that T is the template parameter of the optional template itself. gubbins (talk) 18:51, 2 March 2017 (PST)