fork download
  1. #include <iostream>
  2.  
  3. #include <boost/optional.hpp>
  4.  
  5. struct A
  6. {
  7.  
  8. };
  9.  
  10. int main()
  11. {
  12. boost::optional <A> opt;
  13. opt = {}; // nope!
  14. if (opt)
  15. std::cout << "is initialized?\n";
  16. opt = A{};
  17. if (opt)
  18. std::cout << "is initialized now!\n";
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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 )
               ^~~~~~~~
stdout
Standard output is empty