Boost 1.30.0: Problems with lexical_cast together with unsigned short and MSVC7
The code fragment below does not compile. The problem seems to be related to wide character support. MSVC6 works without problems. #include <boost/lexical_cast.hpp> int main(void) { boost::lexical_cast<std::string,unsigned short>(4); return 0; } Here are the resulting error messages: C:\devel\BOOST\1.30.0\win32-msvc7\include\boost\lexical_cast.hpp(162) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::basic_stringstream<_Elem,_Traits,_Alloc>::_Mystr' (or there is no acceptable conversion) with [ _Elem=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t> ] C:\devel\BOOST\1.30.0 \win32-msvc7\include\boost\lexical_cast.hpp(158) : while compiling class-template member function 'bool boost::detail::lexical_stream<Target,Source>::operator >>(std::string &)' with [ Target=std::string, Source=unsigned short ] C:\devel\BOOST\1.30.0 \win32-msvc7\include\boost\lexical_cast.hpp(190) : see reference to class template instantiation 'boost::detail::lexical_stream<Target,Source>' being compiled with [ Target=std::string, Source=unsigned short ] C:\devel\ICOSOFT\PROJECTS\Applications\H\HelloWorld\main.cpp(5) : see reference to function template instantiation 'Target boost::lexical_cast?$@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@G(Source)' being compiled with [ Target=std::string, Source=unsigned short ] Best regards, Peter.
The code fragment below does not compile. The problem seems to be related to wide character support. MSVC6 works without problems.
#include <boost/lexical_cast.hpp> int main(void) { boost::lexical_cast<std::string,unsigned short>(4); return 0; }
Meanwhile I found the cause of the problem. wchar_t is mapped to unsigned short by default when using MSVC7. To solve the problem, use the compiler flag /Zc:wchar_t. This makes wchar_t a type of its own, independent of unsigned short. So the template specialization for wchar_t is not used and the above code compiles. Best regards, Peter.
participants (2)
-
p.klotz@icoserve.com
-
Peter Klotz