I am attempting to compare two std::map<string,string> objects in
Boost.Test
but am finding that it is trying to stream the std::pair< const
string, string >
that results from dereferencing the iterator.
/* Simplified Example */
AUTO_TEST_CASE( Map_Same )
{
std::map< std::string, std::string > x;
std::map< std::string, std::string > y;
BOOST_CHECK_EQUAL_COLLECTIONS( x.begin(), x.end(), y.begin(),
y.end() );
}
Results in:
/usr/include/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::pair<const
std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >]’:
/usr/include/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 = std::_Rb_tree_iterator<std::pair<const
std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >
>, Right = std::_Rb_tree_iterator<std::pair<const
std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >
>]’
In my application the values a particular entry in the map will not
reveal the problem, so I chose to suppress printing of the pair:
typedef std::pair< const
std::basic_string<char>,std::basic_string<char> >
pair_type;
BOOST_TEST_DONT_PRINT_LOG_VALUE( pair_type );
But alas, this did absolutely nothing. Confused, I tried:
BOOST_CHECK_EQUAL( *x.begin(), *y.begin() );
And it compiled. Remove the suppression and the error returns. So the
suppression works, just not in conjunction with
BOOST_*_EQUAL_COLLECTIONS.
Searching the mailing list revealed a post from 2005.
http://article.gmane.org/gmane.comp.lib.boost.user/13146
He mentions as I also found that equal_coll_impl
uses the stream operator directly on the dereferenced iterators. This
*appears* to be bypassing the code that allows suppression. Though I
may be wrong (I can rarely tell with boost).
Can someone check on this and see if I am crazy? In the mean time I
guess I just have to overload the stream operator.
Regards,
Thomas Suckow