|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85686 - in trunk: boost/range boost/range/algorithm libs/range/test libs/range/test/adaptor_test libs/range/test/algorithm_test libs/range/test/compile_fail libs/range/test/test_driver
From: neil_at_[hidden]
Date: 2013-09-15 15:44:37
Author: neilgroves
Date: 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013)
New Revision: 85686
URL: http://svn.boost.org/trac/boost/changeset/85686
Log:
[boost][range] - fix for ticket 6888 - unique predicate overloads
Added:
trunk/libs/range/test/test_driver/range_overload_test_driver.hpp (contents, props changed)
Text files modified:
trunk/boost/range/algorithm/unique.hpp | 6 +-
trunk/boost/range/config.hpp | 6 ++
trunk/libs/range/test/adaptor_test/strided.cpp | 10 ++-
trunk/libs/range/test/algorithm.cpp | 7 ++
trunk/libs/range/test/algorithm_test/unique.cpp | 94 ++++++++++++++++++++++++++++++++++++---
trunk/libs/range/test/compile_fail/iterator_range1.cpp | 1
trunk/libs/range/test/test_driver/range_overload_test_driver.hpp | 74 +++++++++++++++++++++++++++++++
7 files changed, 183 insertions(+), 15 deletions(-)
Modified: trunk/boost/range/algorithm/unique.hpp
==============================================================================
--- trunk/boost/range/algorithm/unique.hpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/boost/range/algorithm/unique.hpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -86,14 +86,14 @@
/// \overload
template< class ForwardRange, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
-unique( ForwardRange& rng, BinaryPredicate )
+unique( ForwardRange& rng, BinaryPredicate pred )
{
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
- return ::boost::range::unique<return_begin_found>(rng);
+ return ::boost::range::unique<return_begin_found>(rng, pred);
}
/// \overload
template< class ForwardRange, class BinaryPredicate >
-inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
+inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
unique( const ForwardRange& rng, BinaryPredicate pred )
{
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
Modified: trunk/boost/range/config.hpp
==============================================================================
--- trunk/boost/range/config.hpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/boost/range/config.hpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -48,6 +48,12 @@
#define BOOST_RANGE_ARRAY_REF() (&boost_range_array)
#endif
+#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
+# define BOOST_RANGE_UNUSED __attribute__((unused))
+#else
+# define BOOST_RANGE_UNUSED
+#endif
+
#endif
Modified: trunk/libs/range/test/adaptor_test/strided.cpp
==============================================================================
--- trunk/libs/range/test/adaptor_test/strided.cpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/libs/range/test/adaptor_test/strided.cpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -13,6 +13,7 @@
//
#include <boost/range/adaptor/strided.hpp>
+#include <boost/config.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
@@ -42,9 +43,12 @@
Container reference;
{
- typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iterator_t;
- typedef BOOST_DEDUCED_TYPENAME Container::difference_type diff_t;
- typedef BOOST_DEDUCED_TYPENAME Container::size_type size_type;
+ typedef BOOST_DEDUCED_TYPENAME Container::const_iterator
+ iterator_t BOOST_RANGE_UNUSED;
+ typedef BOOST_DEDUCED_TYPENAME Container::difference_type
+ diff_t BOOST_RANGE_UNUSED;
+ typedef BOOST_DEDUCED_TYPENAME Container::size_type
+ size_type BOOST_RANGE_UNUSED;
iterator_t it = c.begin();
iterator_t last = c.end();
Modified: trunk/libs/range/test/algorithm.cpp
==============================================================================
--- trunk/libs/range/test/algorithm.cpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/libs/range/test/algorithm.cpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -35,6 +35,7 @@
#endif
#include <boost/assign.hpp>
+#include <boost/config.hpp>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <boost/range/numeric.hpp>
@@ -107,9 +108,11 @@
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Rng>::type iterator;
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Rng>::type value_type;
- typedef BOOST_DEDUCED_TYPENAME boost::range_size<Rng>::type size_type;
+ typedef BOOST_DEDUCED_TYPENAME boost::range_size<Rng>::type size_type BOOST_RANGE_UNUSED;
typedef BOOST_DEDUCED_TYPENAME boost::iterator_category<iterator>::type iterator_category;
+
+
// just make sure these compile (for now)
if(0)
{
@@ -328,6 +331,8 @@
o = boost::adjacent_difference( rng, boost::begin(out) );
o = boost::adjacent_difference( rng, boost::begin(out),
null_op2() );
+
+ boost::ignore_unused_variable_warning(b);
}
Modified: trunk/libs/range/test/algorithm_test/unique.cpp
==============================================================================
--- trunk/libs/range/test/algorithm_test/unique.cpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/libs/range/test/algorithm_test/unique.cpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -9,13 +9,15 @@
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/range/algorithm/unique.hpp>
+#include <boost/range/detail/range_return.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
-#include "../test_driver/range_return_test_driver.hpp"
+#include <boost/config.hpp>
+#include "../test_driver/range_overload_test_driver.hpp"
#include <algorithm>
#include <functional>
#include <list>
@@ -60,6 +62,36 @@
}
};
+ template<typename Container>
+ struct test_range_overload
+ {
+ BOOST_STATIC_CONSTANT(
+ ::boost::range_return_value,
+ result_type = ::boost::return_begin_found);
+
+ template<typename Policy>
+ BOOST_DEDUCED_TYPENAME boost::range_return<
+ Container, result_type
+ >::type
+ operator()(Policy& policy, Container& cont)
+ {
+ typedef BOOST_DEDUCED_TYPENAME boost::range_return<
+ Container,result_type>::type result_t;
+
+ Container cont2(cont);
+
+ result_t result = boost::unique(cont);
+
+ boost::unique(boost::make_iterator_range(cont2));
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ cont.begin(), cont.end(),
+ cont2.begin(), cont2.end());
+
+ return result;
+ }
+ };
+
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
@@ -67,7 +99,7 @@
return std::unique(cont.begin(), cont.end());
}
};
-
+
// test the 'unique' algorithm with a predicate
template<class Pred>
class unique_pred_test_policy
@@ -105,6 +137,34 @@
return result;
}
};
+
+ template<typename Container>
+ struct test_range_overload
+ {
+ BOOST_STATIC_CONSTANT(
+ ::boost::range_return_value,
+ result_type = ::boost::return_begin_found);
+
+ template<typename Policy>
+ BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
+ operator()(Policy& policy, Container& cont)
+ {
+ typedef BOOST_DEDUCED_TYPENAME boost::range_return<
+ Container,result_type>::type result_t;
+
+ Container cont2(cont);
+
+ result_t result = boost::unique(cont, policy.pred());
+
+ boost::unique(boost::make_iterator_range(cont2), policy.pred());
+
+ BOOST_CHECK_EQUAL_COLLECTIONS(
+ cont.begin(), cont.end(),
+ cont2.begin(), cont2.end());
+
+ return result;
+ }
+ };
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
@@ -121,7 +181,7 @@
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
- boost::range_test::range_return_test_driver test_driver;
+ boost::range_test::range_overload_test_driver test_driver;
Container cont;
@@ -145,6 +205,19 @@
test_driver(cont, policy);
}
+
+ template<typename T>
+ struct equal_div_2
+ {
+ typedef bool result_type;
+ typedef const T& first_argument_type;
+ typedef const T& second_argument_type;
+
+ bool operator()(const T& left, const T& right) const
+ {
+ return left / 2 == right / 2;
+ }
+ };
template<class Container>
void test_unique_impl()
@@ -152,17 +225,22 @@
test_unique_impl<Container>(
unique_test_policy(),
std::less<int>()
- );
+ );
test_unique_impl<Container>(
- unique_pred_test_policy<std::less<int> >(),
+ unique_pred_test_policy<std::equal_to<int> >(),
std::less<int>()
- );
+ );
test_unique_impl<Container>(
- unique_pred_test_policy<std::greater<int> >(),
+ unique_pred_test_policy<std::equal_to<int> >(),
std::greater<int>()
- );
+ );
+
+ test_unique_impl<Container>(
+ unique_pred_test_policy<equal_div_2<int> >(),
+ std::less<int>()
+ );
}
void test_unique()
Modified: trunk/libs/range/test/compile_fail/iterator_range1.cpp
==============================================================================
--- trunk/libs/range/test/compile_fail/iterator_range1.cpp Sun Sep 15 15:38:08 2013 (r85685)
+++ trunk/libs/range/test/compile_fail/iterator_range1.cpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -16,6 +16,7 @@
{
double source[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
boost::iterator_range<float*> rng = boost::make_iterator_range(source);
+ boost::ignore_unused_variable_warning(rng);
}
}
Added: trunk/libs/range/test/test_driver/range_overload_test_driver.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/range/test/test_driver/range_overload_test_driver.hpp 2013-09-15 15:44:36 EDT (Sun, 15 Sep 2013) (r85686)
@@ -0,0 +1,74 @@
+ // Copyright Neil Groves 2013. Use, modification and
+ // distribution is subject to the Boost Software License, Version
+ // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+ // http://www.boost.org/LICENSE_1_0.txt)
+ //
+ //
+ // For more information, see http://www.boost.org/libs/range/
+ //
+ // Acknowledgments:
+ // Implemented by Andy in response to Ticket 6888 - unique fix
+ //
+ #ifndef BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED
+ #define BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED
+
+ #include "range_return_test_driver.hpp"
+ #include <boost/assert.hpp>
+ #include <boost/test/test_tools.hpp>
+ #include <boost/test/unit_test.hpp>
+
+ namespace boost
+ {
+ namespace range_test
+ {
+
+ // A test driver to exercise a test through range_return_test_driver
+ // plus the overload that determines the return_type by overload
+ //
+ // The test driver also contains the code required to check the
+ // return value correctness.
+ //
+ // The TestPolicy needs to implement all those required by
+ // range_return_test_driver, and additionally
+ //
+ // - perform the boost range version of the algorithm that determines
+ // the return_type by overload
+ class range_overload_test_driver : range_return_test_driver
+ {
+ public:
+ template< class Container,
+ class TestPolicy >
+ void operator()(Container& cont, TestPolicy policy)
+ {
+ range_return_test_driver::operator()(cont, policy);
+ test_range_overload<Container, TestPolicy>()(cont, policy);
+ }
+
+ private:
+ template< class Container, class TestPolicy >
+ struct test_range_overload
+ {
+ void operator()(Container& cont, TestPolicy policy)
+ {
+ typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
+ typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range_overload<Container> test_range_overload_t;
+ const range_return_value result_type = test_range_overload_t::result_type;
+ typedef BOOST_DEDUCED_TYPENAME range_return<Container, result_type>::type range_return_t;
+
+ Container reference(cont);
+ Container test_cont(cont);
+
+ test_range_overload_t test_range_overload_fn;
+ range_return_t range_result = test_range_overload_fn(policy, test_cont);
+
+ iterator_t reference_it = policy.reference(reference);
+
+ check_results<result_type>::test(test_cont, reference,
+ range_result, reference_it);
+ }
+ };
+ };
+ }
+ }
+
+ #endif // include guard
\ No newline at end of file
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