My environment is Visual Stuido 2013, VC12, Boost 1.59. The following code (a minimal repro of the real code):
#include "boost/thread.hpp"
#include "boost/optional.hpp"
class MyClass
{
public:
template <typename T>
operator const T& () const;
};
boost::optional<MyClass> foo()
{
boost::optional<MyClass> res;
return res;
}
int main(int argc)
{
foo();
}
Doesn't compile, the error:
1>------ Build started: Project: TestBoostOptional, Configuration: Debug x64 ------ 1> main.cpp 1>c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(297): error C2664: 'void boost::optional_detail::optional_base::construct(MyClass &&)' : cannot convert argument 1 from 'boost::detail::thread_move_t' to 'const MyClass &' 1> with 1> [ 1> T=MyClass 1> ] 1> Reason: cannot convert from 'boost::detail::thread_move_t' to 'const MyClass' 1> with 1> [ 1> T=MyClass 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(292) : while compiling class template member function 'boost::optional_detail::optional_base::optional_base(boost::optional_detail::optional_base &&)' 1> with 1> [ 1> T=MyClass 1> ] 1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(873) : see reference to function template instantiation 'boost::optional_detail::optional_base::optional_base(boost::optional_detail::optional_base &&)' being compiled 1> with 1> [ 1> T=MyClass 1> ] 1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(766) : see reference to class template instantiation 'boost::optional_detail::optional_base' being compiled 1> with 1> [ 1> T=MyClass 1> ] 1> main.cpp(14) : see reference to class template instantiation 'boost::optional' being compiled
Note the #include "boost/thread.hpp"
. When removing this include the code compiles. Anything that can be done to workaround?