Boost logo

Boost :

From: Jens Theisen (jth01_at_[hidden])
Date: 2006-03-06 14:51:00


Hello,

what do people think about Boost.Range support?

Instead of writing

my_range_type r = <complex expression>;

std::vector< int > v = list_of(1)(2)(3);

BOOST_CHECK_EQUAL_COLLECTIONS(r.begin(), r.end(), v.begin(), v.end());

one could write more conveniently the single line

BOOST_CHECK_EQUAL_RANGES( <complex expression>, list_of(1)(2)(3) );

It's also more readable and would so improve the documentational aspect of
tests.

(Is it ok to post short diffs as this?)

Index: boost/test/test_tools.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/test/test_tools.hpp,v
retrieving revision 1.59
diff -u -r1.59 test_tools.hpp
--- boost/test/test_tools.hpp 3 Mar 2006 17:39:46 -0000 1.59
+++ boost/test/test_tools.hpp 6 Mar 2006 19:50:52 -0000
@@ -33,6 +33,7 @@
 #include <boost/preprocessor/repetition/repeat.hpp>
 #include <boost/preprocessor/punctuation/comma_if.hpp>
 #include <boost/preprocessor/arithmetic/add.hpp>
+#include <boost/range/functions.hpp>
 #include <boost/limits.hpp>

 #include <boost/type_traits/is_array.hpp>
@@ -222,6 +223,22 @@

 //____________________________________________________________________________//

+#define BOOST_EQUAL_RANGES_IMPL( L, R, TL ) \
+ BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_range_impl( \
+ (L), (R) ), "", TL, CHECK_EQUAL_COLL ), \
+ 2, \
+ BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) ) \
+/**/
+
+#define BOOST_WARN_EQUAL_RANGES( L, R ) \
+ BOOST_EQUAL_RANGES_IMPL( L, R, WARN )
+#define BOOST_CHECK_EQUAL_RANGES( L, R ) \
+ BOOST_EQUAL_RANGES_IMPL( L, R, CHECK )
+#define BOOST_REQUIRE_EQUAL_RANGES( L, R ) \
+ BOOST_EQUAL_RANGES_IMPL( L, R, REQUIRE )
+
+//____________________________________________________________________________//
+
 #define BOOST_BITWISE_EQUAL_IMPL( L, R, TL ) \
     BOOST_TEST_TOOL_IMPL( check_impl, \
       ::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ), \
@@ -547,6 +564,16 @@

 //____________________________________________________________________________//

+template <typename Left, typename Right>
+inline predicate_result
+equal_range_impl( Left const& left, Right const& right )
+{
+ return equal_coll_impl( boost::begin(left), boost::end(left),
+ boost::begin(right), boost::end(right) );
+}
+
+//____________________________________________________________________________//
+
 template <class Left, class Right>
 inline predicate_result
 bitwise_equal_impl( Left const& left, Right const& right )


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