Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2008-02-17 11:42:06


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk