This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of LEWG status.

2825. LWG 2756 breaks class template argument deduction for optional

Section: 20.6.3 [optional.optional] Status: LEWG Submitter: Richard Smith Opened: 2016-11-24 Last modified: 2017-02-01

Priority: 2

View other active issues in [optional.optional].

View all other issues in [optional.optional].

View all issues with LEWG status.


LWG 2756 applies these changes:

constexpr optional(const T&);
constexpr optional(T&&);
template <class... Args> constexpr explicit optional(in_place_t, Args&&...);
template <class U, class... Args>
  constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
template <class U = T> EXPLICIT constexpr optional(U&&);
template <class U> EXPLICIT optional(const optional<U>&);
template <class U> EXPLICIT optional(optional<U>&&);

These break the ability for optional to perform class template argument deduction, as there is now no way to map from optional's argument to the template parameter T.

[2017-01-27 Telecon]

Priority 2

[2017-01-30 Ville comments:]

Seems like the problem is resolved by a simple deduction guide:

template <class T> optional(T) -> optional<T>;

The paper p0433r0 seems to suggest a different guide,

template<class T> optional(T&& t) -> optional<remove_reference_t<T>>;

but I don't think the paper is up to speed with LWG 2756. There's no reason to use such an universal reference in the guide and remove_reference in its target, just guide with T, with the target optional<T>, optional's constructors do the right thing once the type has been deduced.

Proposed resolution: