I'm using boost::numeric_cast to convert the size of a wstring (presumably
a size_t) to an int.
const int size = boost::numeric_cast<int>(my_string.size());
MSVC still gives me a warning about possible loss of data:
c:\program files\boost\boost_1_38\boost\numeric\conversion\
cast.hpp(41) : warning C4267: 'argument' : conversion from 'size_t'
to 'unsigned int', possible loss of data
c:\users\awl03\documents\visual studio 2005\projects\swish_trunk
(padd)\swish\utils.hpp(91) : see reference to function template
instantiation 'Target boost::numeric_cast(Source)' being compiled
with
[
Target=int,
Source=__w64 unsigned int
]
c:\users\awl03\documents\visual studio 2005\projects\swish_trunk
(padd)\swish\utils.hpp(121) : see reference to function template
instantiation 'std::basic_string<_Elem,_Traits,_Ax>
swish::utils::ConvertString<`anonymous-namespace'::Narrow>(const
std::basic_string,std::
allocator<_Ty>> &)' being compiled
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>,
_Ty=wchar_t
]
Unless I misunderstand, isn't the idea of numeric_cast that warnings aren't
needed because the casts are checked for loss of data? Any advice is
greatly appreaciated.
I am using the MSVC 8.0 compiler with Boost 1.38.0 on 32-bit Windows Vista.
Thanks.
Alex Lamaison