[Boost-users] BOOST_CHECK_EQUAL_COLLECTIONS fails to compile when comparing vector<wstring>

183 views
Skip to first unread message

Mauricio Gomes

unread,
Apr 13, 2009, 9:56:57 PM4/13/09
to boost...@lists.boost.org
Hi,
I am using Windows XP, boost 1.38 and mingw 3.4.5 (Code::Blocks IDE).
I cannot compile BOOST_CHECK_EQUAL_COLLECTIONS when using wstring. See below:

#define CHECK_EQUAL_COLLECTIONS(L, R)         \
  BOOST_CHECK_EQUAL_COLLECTIONS((L).begin (), (L).end (), (R).begin (), (R).end ())

vector<string > v1;
vector<wstring> v2;

CHECK_EQUAL_COLLECTIONS(v1, v1); // this compiles fine.
CHECK_EQUAL_COLLECTIONS(v2, v2); // this gives me the error listed below (at the end).

Searching for a solution I've found this: http://lists.boost.org/boost-users/2005/09/13720.php
And in fact, adding the code below solves it.
namespace std
{
    ostream& operator << (ostream& ostr, wstring const& str)
    {
       ostr << boost::lexical_cast<wstring>(str);
       return ostr;
    }
}

However this seems somewhat clumsy to me.
I do not like the idea of doing a cast like this that obviously can fail if the wstring has a wide char that cannot be mapped to char properly. And it seems inappropriate to require the user to define such a thing.
Is there a better way of solving this ? Can anything be done in the unit test framework itself to solve this in a better way ?

I am a beginner with template metaprogramming so I ask the experts here to tell me if there is a better way or if that's the way it is and nothing can be done.

Thank you for your attention !
Mauricio.

c:\boost_1_38_0\boost\test\utils\wrap_stringstream.hpp||In function `boost::basic_wrap_stringstream<CharT>& boost::operator<<(boost::basic_wrap_stringstream<CharT>&, const T&) [with CharT = char, T = std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >]':|
c:\boost_1_38_0\boost\test\test_tools.hpp|641|instantiated from `boost::test_tools::predicate_result boost::test_tools::tt_detail::equal_coll_impl(Left, Left, Right, Right) [with Left = __gnu_cxx::__normal_iterator<std::wstring*, std::vector<std::wstring, std::allocator<std::wstring> > >, Right = __gnu_cxx::__normal_iterator<std::wstring*, std::vector<std::wstring, std::allocator<std::wstring> > >]'|
C:\projects\cpplib\source\test\string_util_test.cpp|71|instantiated from here|
c:\boost_1_38_0\boost\test\utils\wrap_stringstream.hpp|66|error: no match for 'operator<<' in '(+targ)->boost::basic_wrap_stringstream<CharT>::stream [with CharT = char]() << t'|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|63|note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|74|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|86|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|121|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|155|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|98|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ostream|178|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ostream|189|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ostream|193|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ostream|204|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|179|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|214|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|238|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ostream|219|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|261|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|284|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]|
C:\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\ostream.tcc|307|note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]|
c:\boost_1_38_0\boost\test\utils\xml_printer.hpp|103|note:                 std::ostream& boost::unit_test::operator<<(const boost::unit_test::custom_printer<boost::unit_test::pcdata>&, boost::unit_test::const_string)|
c:\boost_1_38_0\boost\test\utils\lazy_ostream.hpp|40|note:                 std::ostream& boost::unit_test::operator<<(std::ostream&, const boost::unit_test::lazy_ostream&)|
||=== Build finished: 1 errors, 0 warnings ===|


--
Mauricio Gomes
Pensar Digital
55-11-8319-9610 (Brazil - mobile)

Gennadiy Rozental

unread,
Apr 14, 2009, 1:30:53 AM4/14/09
to boost...@lists.boost.org
Mauricio Gomes <mgpensar <at> gmail.com> writes:

> I cannot compile BOOST_CHECK_EQUAL_COLLECTIONS when using wstring. See

...

> However this seems somewhat clumsy to me.
> I do not like the idea of doing a cast like
> this that obviously can fail if the wstring
> has a wide char that cannot be mapped to char properly.
> And it seems inappropriate to require the user to define
> such a thing.

Unit test framework test tools require an output operation for the values
being compared. That's why you are faced with this issue. Boost.Test is
based on ostreams and there is no operator<< defined for wstring. You
should be able to shutdown output completely for wstring using
BOOST_TEST_DONT_PRINT_LOG_VALUE macro.

Unfortunately complete support for wide string or even more generally for
unicode is not simple project and require significant time investment. I
am not sure at this point when I'll get to it, even though it's on my
todo list.

Gennadiy

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply all
Reply to author
Forward
0 new messages