#include <iostream>
#include <boost/optional.hpp>
struct A
{
};
int main()
{
boost::optional <A> opt;
opt = {}; // nope!
if (opt)
std::cout << "is initialized?\n";
opt = A{};
if (opt)
std::cout << "is initialized now!\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKI2luY2x1ZGUgPGJvb3N0L29wdGlvbmFsLmhwcD4KIApzdHJ1Y3QgQQp7CiAKfTsKIAppbnQgbWFpbigpCnsKICAgIGJvb3N0OjpvcHRpb25hbCA8QT4gb3B0OwogICAgb3B0ID0ge307IC8vIG5vcGUhCiAgICBpZiAob3B0KQogICAgICAgIHN0ZDo6Y291dCA8PCAiaXMgaW5pdGlhbGl6ZWQ/XG4iOwogICAgb3B0ID0gQXt9OwogICAgaWYgKG9wdCkKICAgICAgICBzdGQ6OmNvdXQgPDwgImlzIGluaXRpYWxpemVkIG5vdyFcbiI7CiAgICByZXR1cm4gMDsKfQ==
prog.cpp: In function ‘int main()’:
prog.cpp:13:12: error: ambiguous overload for ‘operator=’ (operand types are ‘boost::optional<A>’ and ‘<brace-enclosed initializer list>’)
opt = {}; // nope!
^
In file included from /usr/include/boost/optional.hpp:15:0,
from prog.cpp:3:
/usr/include/boost/optional/optional.hpp:776:15: note: candidate: boost::optional<T>& boost::optional<T>::operator=(const boost::optional<T>&) [with T = A]
optional& operator= ( optional const& rhs )
^~~~~~~~
/usr/include/boost/optional/optional.hpp:784:15: note: candidate: boost::optional<T>& boost::optional<T>::operator=(boost::optional<T>&&) [with T = A]
optional& operator= ( optional && rhs )
^~~~~~~~
/usr/include/boost/optional/optional.hpp:794:15: note: candidate: boost::optional<T>& boost::optional<T>::operator=(boost::optional<T>::argument_type) [with T = A; boost::optional<T>::argument_type = const A&]
optional& operator= ( argument_type val )
^~~~~~~~
/usr/include/boost/optional/optional.hpp:802:15: note: candidate: boost::optional<T>& boost::optional<T>::operator=(boost::optional<T>::rval_reference_type) [with T = A; boost::optional<T>::rval_reference_type = A&&]
optional& operator= ( rval_reference_type val )
^~~~~~~~