|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70037 - in trunk: boost/range libs/range/test libs/range/test/test_driver
From: neil_at_[hidden]
Date: 2011-03-16 19:34:00
Author: neilgroves
Date: 2011-03-16 19:33:57 EDT (Wed, 16 Mar 2011)
New Revision: 70037
URL: http://svn.boost.org/trac/boost/changeset/70037
Log:
[range] Added <=, ==, >, >=, != operators to iterator_range
Text files modified:
trunk/boost/range/iterator_range_core.hpp | 96 +++++++++++++++++++++++++++++++++
trunk/libs/range/test/iterator_range.cpp | 115 +++++++++++++++++++++++++++++++++++++++
trunk/libs/range/test/test_driver/range_return_test_driver.hpp | 5 +
3 files changed, 212 insertions(+), 4 deletions(-)
Modified: trunk/boost/range/iterator_range_core.hpp
==============================================================================
--- trunk/boost/range/iterator_range_core.hpp (original)
+++ trunk/boost/range/iterator_range_core.hpp 2011-03-16 19:33:57 EDT (Wed, 16 Mar 2011)
@@ -71,6 +71,24 @@
boost::begin(r),
boost::end(r) );
}
+
+ template< class Left, class Right >
+ inline bool greater_than( const Left& l, const Right& r )
+ {
+ return less_than(r,l);
+ }
+
+ template< class Left, class Right >
+ inline bool less_or_equal_than( const Left& l, const Right& r )
+ {
+ return !iterator_range_detail::less_than(r,l);
+ }
+
+ template< class Left, class Right >
+ inline bool greater_or_equal_than( const Left& l, const Right& r )
+ {
+ return !iterator_range_detail::less_than(l,r);
+ }
// This version is maintained since it is used in other boost libraries
// such as Boost.Assign
@@ -271,6 +289,21 @@
{
return iterator_range_detail::less_than( *this, r );
}
+
+ bool operator>( const iterator_range& r ) const
+ {
+ return iterator_range_detail::greater_than( *this, r );
+ }
+
+ bool operator<=( const iterator_range& r ) const
+ {
+ return iterator_range_detail::less_or_equal_than( *this, r );
+ }
+
+ bool operator>=( const iterator_range& r ) const
+ {
+ return iterator_range_detail::greater_or_equal_than( *this, r );
+ }
#endif
@@ -370,6 +403,27 @@
{
return iterator_range_detail::less_than( l, r );
}
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator<=( const ForwardRange& l,
+ const iterator_range<IteratorT>& r )
+ {
+ return iterator_range_detail::less_or_equal_than( l, r );
+ }
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator>( const ForwardRange& l,
+ const iterator_range<IteratorT>& r )
+ {
+ return iterator_range_detail::greater_than( l, r );
+ }
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator>=( const ForwardRange& l,
+ const iterator_range<IteratorT>& r )
+ {
+ return iterator_range_detail::greater_or_equal_than( l, r );
+ }
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#else
@@ -416,6 +470,48 @@
{
return iterator_range_detail::less_than( l, r );
}
+
+ template< class Iterator1T, class Iterator2T >
+ inline bool operator<=( const iterator_range<Iterator1T>& l,
+ const iterator_range<Iterator2T>& r )
+ {
+ return iterator_range_detail::less_or_equal_than( l, r );
+ }
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator<=( const iterator_range<IteratorT>& l,
+ const ForwardRange& r )
+ {
+ return iterator_range_detail::less_or_equal_than( l, r );
+ }
+
+ template< class Iterator1T, class Iterator2T >
+ inline bool operator>( const iterator_range<Iterator1T>& l,
+ const iterator_range<Iterator2T>& r )
+ {
+ return iterator_range_detail::greater_than( l, r );
+ }
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator>( const iterator_range<IteratorT>& l,
+ const ForwardRange& r )
+ {
+ return iterator_range_detail::greater_than( l, r );
+ }
+
+ template< class Iterator1T, class Iterator2T >
+ inline bool operator>=( const iterator_range<Iterator1T>& l,
+ const iterator_range<Iterator2T>& r )
+ {
+ return iterator_range_detail::greater_or_equal_than( l, r );
+ }
+
+ template< class IteratorT, class ForwardRange >
+ inline bool operator>=( const iterator_range<IteratorT>& l,
+ const ForwardRange& r )
+ {
+ return iterator_range_detail::greater_or_equal_than( l, r );
+ }
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
Modified: trunk/libs/range/test/iterator_range.cpp
==============================================================================
--- trunk/libs/range/test/iterator_range.cpp (original)
+++ trunk/libs/range/test/iterator_range.cpp 2011-03-16 19:33:57 EDT (Wed, 16 Mar 2011)
@@ -24,6 +24,7 @@
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
+#include <vector>
void check_reference_type();
@@ -102,17 +103,127 @@
check_reference_type();
}
+namespace iterator_range_test_detail
+{
+ struct less
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l < r;
+ }
+ };
+
+ struct greater
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l > r;
+ }
+ };
+
+ struct less_or_equal
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l <= r;
+ }
+ };
+
+ struct greater_or_equal
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l >= r;
+ }
+ };
+
+ struct equal_to
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l == r;
+ }
+ };
+
+ struct not_equal_to
+ {
+ template< class Left, class Right >
+ bool operator()(const Left& l, const Right& r) const
+ {
+ return l != r;
+ }
+ };
+
+ template< class Pred >
+ void check_iterator_range_operators_impl(Pred pred)
+ {
+ std::vector<std::string> vals;
+ vals.push_back(std::string());
+ vals.push_back("a");
+ vals.push_back("b");
+ vals.push_back("z");
+ vals.push_back("ab");
+ vals.push_back("ba");
+ vals.push_back("abc");
+ vals.push_back("cba");
+ vals.push_back("aa");
+ vals.push_back("aaa");
+ vals.push_back("aab");
+ vals.push_back("bba");
+
+ typedef std::string::const_iterator citer;
+ typedef boost::iterator_range<citer> iter_range;
+
+ typedef std::vector<std::string>::const_iterator value_const_iterator;
+ value_const_iterator first_val = vals.begin();
+ value_const_iterator last_val = vals.end();
+
+ for (value_const_iterator left_it = first_val; left_it != last_val; ++left_it)
+ {
+ const std::string& leftValue = *left_it;
+ for (value_const_iterator right_it = first_val; right_it != last_val; ++right_it)
+ {
+ const std::string& rightValue = *right_it;
+ iter_range left = boost::make_iterator_range(leftValue);
+ iter_range right = boost::make_iterator_range(rightValue);
+
+ const bool reference = pred(leftValue, rightValue);
+
+ BOOST_CHECK_EQUAL( pred(left, right), reference );
+ BOOST_CHECK_EQUAL( pred(left, rightValue), reference );
+ BOOST_CHECK_EQUAL( pred(leftValue, right), reference );
+ }
+ }
+ }
+} // namespace iterator_range_test_detail
+
+template<typename Pred>
+inline void check_iterator_range_operator()
+{
+ iterator_range_test_detail::check_iterator_range_operators_impl(
+ Pred());
+}
boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
{
boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
- test->add( BOOST_TEST_CASE( &check_iterator_range ) );
+ test->add(BOOST_TEST_CASE(&check_iterator_range));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::less>));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::less_or_equal>));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::greater>));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::greater_or_equal>));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::equal_to>));
+ test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::not_equal_to>));
return test;
}
-
//
//
// Check that constness is propgated correct from
Modified: trunk/libs/range/test/test_driver/range_return_test_driver.hpp
==============================================================================
--- trunk/libs/range/test/test_driver/range_return_test_driver.hpp (original)
+++ trunk/libs/range/test/test_driver/range_return_test_driver.hpp 2011-03-16 19:33:57 EDT (Wed, 16 Mar 2011)
@@ -371,7 +371,7 @@
Container reference(cont);
Container test(cont);
-
+
iterator_t range_result = policy.test_iter(test);
iterator_t reference_it = policy.reference(reference);
@@ -391,7 +391,8 @@
Container reference(cont);
Container test_cont(cont);
- range_return_t range_result = test_range_t()(policy, test_cont);
+ test_range_t test_range_fn;
+ range_return_t range_result = test_range_fn(policy, test_cont);
iterator_t reference_it = policy.reference(reference);
check_results<result_type>::test(test_cont, reference,
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk