[Boost.Test] should we add operator<<() for standard containers etc

Hi Gennadiy, I've just implemented some comparison operators for Boost.Assign's list_of(): typedef std::vector<int> Seq; BOOST_CHECK_EQUAL( ba::list_of(0)(1)(2), (Seq)ba::list_of(0)(1)(2) ); BOOST_CHECK_NE( ba::list_of(0)(1)(2), (Seq)ba::list_of(-1)(1)(2) ); BOOST_CHECK_LT( ba::list_of(0)(1)(2), (Seq)ba::list_of(0)(1)(3) ); BOOST_CHECK_LE( ba::list_of(0)(1)(2), (Seq)ba::list_of(0)(1)(2) ); BOOST_CHECK_GT( ba::list_of(0)(1)(3), (Seq)ba::list_of(0)(1)(2) ); BOOST_CHECK_GE( ba::list_of(0)(1)(2), (Seq)ba::list_of(0)(1)(2) ); This works, but I need to specify how to stream the other type of argument, in this case an std::vector<int> object: namespace std { template< class T, class Elem, class Traits > inline std::basic_ostream<Elem,Traits>& operator<<( std::basic_ostream<Elem, Traits>& Os, const std::vector<T>& r ) { return Os << ::boost::make_iterator_range( r.begin(), r.end() ); } } Since there are so many ranges out there, mabe it would be better to add the following. We already have BOOST_CHECK_EQUAL_COLLECTIONS(x,y,z,w) (but where is BOOST_CHECK_NE_COLLECTIONS etc?) then why not add BOOST_CHECK_EQUAL_RANGE( Rng1, Rng2 ) // implement by calling make_iterator_range() on the two arguments Also, I would like to see BOOST_CHECK_NE_RANGE( Rng1, Rng2 ) BOOST_CHECK_GT_RANGE( Rng1, Rng2 ) BOOST_CHECK_GE_RANGE( Rng1, Rng2 ) BOOST_CHECK_LT_RANGE( Rng1, Rng2 ) BOOST_CHECK_LE_RANGE( Rng1, Rng2 ) Any thoughts? -Thorsten

Thorsten Ottosen <thorsten.ottosen <at> dezide.com> writes:
then why not add
BOOST_CHECK_EQUAL_RANGE( Rng1, Rng2 )
// implement by calling make_iterator_range() on the two arguments
Also, I would like to see
BOOST_CHECK_NE_RANGE( Rng1, Rng2 ) BOOST_CHECK_GT_RANGE( Rng1, Rng2 ) BOOST_CHECK_GE_RANGE( Rng1, Rng2 ) BOOST_CHECK_LT_RANGE( Rng1, Rng2 ) BOOST_CHECK_LE_RANGE( Rng1, Rng2 )
I guess it make sence now. The only problem I would prefer to avoid extra dependency on range library. I can put it into separate header. Gennadiy

Gennadiy Rozental skrev:
Thorsten Ottosen <thorsten.ottosen <at> dezide.com> writes:
then why not add
BOOST_CHECK_EQUAL_RANGE( Rng1, Rng2 )
// implement by calling make_iterator_range() on the two arguments
Actually, this is too naive an implementation as iterator_range<> lacks
,>=,<=. Hm. Maybe I should add those.
There is one more annoyance, I think. std::pair<T,U> lacks a operator<<() which means the following will fail: BOOST_CHECK_EQUAL_RANGE( ba::map_list_of("foo",1)("bar",2), get_map() ); Is it reasonable that operator<<() is required when we simply want to test comparison with ==? Perhaps there should be a way to get rid of that requirement?
Also, I would like to see
BOOST_CHECK_NE_RANGE( Rng1, Rng2 ) BOOST_CHECK_GT_RANGE( Rng1, Rng2 ) BOOST_CHECK_GE_RANGE( Rng1, Rng2 ) BOOST_CHECK_LT_RANGE( Rng1, Rng2 ) BOOST_CHECK_LE_RANGE( Rng1, Rng2 )
I guess it make sence now. The only problem I would prefer to avoid extra dependency on range library. I can put it into separate header.
That is quite ok. Just include everything in that header then. -Thorsten

"Thorsten Ottosen" <thorsten.ottosen@dezide.com> wrote in message news:47B9E537.6040904@dezide.com...
BOOST_CHECK_EQUAL_RANGE( ba::map_list_of("foo",1)("bar",2), get_map() );
Is it reasonable that operator<<() is required when we simply want to test comparison with ==? Perhaps there should be a way to get rid of that requirement?
There is. Use BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ). Gennadiy
participants (2)
-
Gennadiy Rozental
-
Thorsten Ottosen