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)
[edit] explicit constructors
Why is explicit in a comment? It's not in a comment here: http://en.cppreference.com/w/cpp/container/vector/vector 2620:0:1000:8000:ACAE:4A00:D7A8:BA35 17:37, 12 February 2018 (PST)
- here it is conditionally-explicit, the description below the declaration explains when it is and when it isn't. Perhaps we should use a different presentation, like (conditionally-explicit)--Cubbi (talk) 18:06, 12 February 2018 (PST)
[edit] The condition for the 7th ctor
I believe the condition for the 7th ctor should be std::is_constructible_v<T, std::initializer_list<U>&, Args...> (no double ampersand after Args), though I'm not sure.
2A02:6B8:0:40C:99CD:2BDB:50CA:440 08:41, 29 October 2018 (PDT)