
I'm having an issue testing against wstrings: std::wstring testString(""); BOOST_CHECK_EQUAL(testString,L""); This fails with the following error: std_map.cpp: In member function ‘void vector_in_map_stream_test::test_method()’: std_map.cpp:83: error: no matching function for call to ‘std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(const char [1])’ /usr/include/c++/4.0.0/bits/basic_string.tcc:232: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(typename _Alloc::size_type, _CharT, const _Alloc&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:225: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:218: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, typename _Alloc::size_type, const _Alloc&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:207: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::size_type, typename _Alloc::size_type, const _Alloc&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:196: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&, typename _Alloc::size_type, typename _Alloc::size_type) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:182: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.tcc:190: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /usr/include/c++/4.0.0/bits/basic_string.h:2027: note: std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, _Alloc = std::allocator<wchar_t>] /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/ test_tools.hpp: In member function ‘void boost::test_tools::print_log_value<T>::operator()(std::ostream&, const T&) [with T = std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >]’: /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/test_tools.hpp: 467: instantiated from ‘std::ostream& boost::test_tools::tt_detail::operator<<(std::ostream&, const boost::test_tools::tt_detail::print_helper_t<T>&) [with T = std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >]’ /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/utils/ lazy_ostream.hpp:74: instantiated from ‘std::ostream& boost::unit_test::lazy_ostream_impl<T>::operator()(std::ostream&) const [with T = const boost ::test_tools::tt_detail::print_helper_t<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >&]’ std_map.cpp:110: instantiated from here /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/test_tools.hpp: 326: error: no match for ‘operator<<’ in ‘ostr << t’ /usr/include/c++/4.0.0/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*) (std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:78: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*) (std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:90: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:125: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:159: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:102: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:176: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:187: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:191: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:202: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:183: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:218: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:242: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:217: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:265: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:288: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:311: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] Is this something that can be worked around without having to convert the string to char? Thanks, Jared

Whoops. In the rush to simplify the example, I hadn't noticed that the error messages had changed. Here is the error when a wstring is properly constructed: /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/ test_tools.hpp: In member function ‘void boost::test_tools::print_log_value<T>::operator()(std::ostream&, const T&) [with T = std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >]’: /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/test_tools.hpp: 467: instantiated from ‘std::ostream& boost::test_tools::tt_detail::operator<<(std::ostream&, const boost::test_tools::tt_detail::print_helper_t<T>&) [with T = std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >]’ /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/utils/ lazy_ostream.hpp:74: instantiated from ‘std::ostream& boost::unit_test::lazy_ostream_impl<T>::operator()(std::ostream&) const [with T = const boost ::test_tools::tt_detail::print_helper_t<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >&]’ std_map.cpp:112: instantiated from here /Users/jared/Source/boost_nobak/boost_1_39_0/boost/test/test_tools.hpp: 326: error: no match for ‘operator<<’ in ‘ostr << t’ /usr/include/c++/4.0.0/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*) (std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:78: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*) (std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:90: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:125: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:159: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:102: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:176: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:187: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:191: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:202: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:183: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:218: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:242: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/ostream:217: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:265: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:288: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>] /usr/include/c++/4.0.0/bits/ostream.tcc:311: note: std::basic_ostream<CharT1, Tr>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] Sorry about that. The following code will work as a workaround, but I was wondering what others are doing when they have a wstring. std::wstring testString; BOOST_CHECK_EQUAL(testString.c_str(), L""); Jared On Aug 26, 2009, at 3:39 PM, Ryan Gallagher wrote:
Jared McIntyre <jmcintyre <at> dfsoftware.com> writes:
I'm having an issue testing against wstrings:
std::wstring testString(""); BOOST_CHECK_EQUAL(testString,L"");
try:
std::wstring testString;
or
std::wstring testString(L"");
-Ryan
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Jared McIntyre <jmcintyre <at> dfsoftware.com> writes:
Whoops. In the rush to simplify the example, I hadn't noticed that the error messages had changed. Here is the error when a wstring is properly constructed:
<snip>
Sorry about that. The following code will work as a workaround, but I was wondering what others are doing when they have a wstring.
std::wstring testString; BOOST_CHECK_EQUAL(testString.c_str(), L"");
Another option is BOOST_CHECK_MESSAGE((testString == L""), "testString doesn't match an empty wcstring!");. Or just define operator<<(std::ostream&, std::wstring const&) in your test module. -Ryan
participants (2)
-
Jared McIntyre
-
Ryan Gallagher