which of the two constructors would the user expect to be called? I guess the former, but he would be surprised. I do not know how to solve this problem. Perhaps someone on the list does.(because this would turn an explicit conversion into an implicit one). Such "conditionally explicit" converting constructor is doable, but I run on another problem. The additional constructors would look like:template <class U>optional::optional(U&& u);template <class U>
optional::optional(optional<U> const& ou);Suppose you have the following class:struct Port
{Port (optional<int> oi);
};optional<int> oi;optional<Port> op = oi;
On Sat, Oct 5, 2013 at 1:14 PM, Andrzej Krzemieński <akrz...@gmail.com> wrote:I don't expect these to work. Within the optional
> Hi Everyone,
> It was suggested by LEWG that the following converting constructor should be
> added to optional:
>
> optional<string> os = "str";
> optional<unique_ptr<Base>> op = unique_ptr<Derived>{};
>
> and probably also this should work:
>
> optional<unique_ptr<Base>> op = optional<unique_ptr<Derived>>{};
domain, we know T -> optional<T> is safe; but
outside this domain, it does not seem to be a good
idea to judge which kind of conversion is safe with
optional instead of just take the decision of C++.
Oh, you spotted a different problem than I did. Mine was that (even if I fixed yours) it is not clear how to handle a case where T has a constructor taking another optional. Consider a more tricky type:
struct Port
{Port (optional<int> oi);
Port (int);
};
And now the code that uses it:Now, forget how optional is or might be implemented. As a user, which constructor of Port would you expect to be called?
optional<int> oi;
optional<Port> op = oi;