From 10af4fc1e091e7f9402e40bcfb3130cb2a6f6629 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Tue, 29 Mar 2011 10:27:00 +0000 Subject: [PATCH 01/14] [boost][range] - Improve the forwarding of the functor, and provide a work-around for the breaking changes in VC10 for_each. [SVN r70690] --- include/boost/range/algorithm/for_each.hpp | 67 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/include/boost/range/algorithm/for_each.hpp b/include/boost/range/algorithm/for_each.hpp index 714a06f..dc2221d 100755 --- a/include/boost/range/algorithm/for_each.hpp +++ b/include/boost/range/algorithm/for_each.hpp @@ -13,13 +13,52 @@ #include #include #include +#include #include +#if BOOST_WORKAROUND(BOOST_MSVC, == 1600) +#include +#endif + namespace boost { namespace range { +#if BOOST_WORKAROUND(BOOST_MSVC, == 1600) + namespace for_each_detail + { + template + inline UnaryFunction + for_each_impl(Iterator first, Iterator last, UnaryFunction fun, + typename enable_if< + is_reference_wrapper, + void + >::type* = 0) + { + typedef typename std::_Get_unchecked_type::type + unchecked_iterator; + + unchecked_iterator unchecked_last = std::_Unchecked(last); + for (unchecked_iterator unchecked_first = std::_Unchecked(first); first != last; ++first) + fun.get()(*unchecked_first); + + return fun; + } + + template + inline UnaryFunction + for_each_impl(Iterator first, Iterator last, UnaryFunction fn, + typename disable_if< + is_reference_wrapper, + void + >::type* = 0) + { + return std::for_each(first, last, fn); + } + } +#endif + /// \brief template function for_each /// /// range-based version of the for_each std algorithm @@ -30,7 +69,18 @@ template< class SinglePassRange, class UnaryFunction > inline UnaryFunction for_each(SinglePassRange & rng, UnaryFunction fun) { BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); - return std::for_each(boost::begin(rng),boost::end(rng),fun); + +#if BOOST_WORKAROUND(BOOST_MSVC, == 1600) + return for_each_detail::for_each_impl< + typename range_iterator::type, + UnaryFunction + >(boost::begin(rng), boost::end(rng), fun); +#else + return std::for_each< + BOOST_DEDUCED_TYPENAME range_iterator::type, + UnaryFunction + >(boost::begin(rng),boost::end(rng),fun); +#endif } /// \overload @@ -38,11 +88,22 @@ template< class SinglePassRange, class UnaryFunction > inline UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun) { BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); - return std::for_each(boost::begin(rng), boost::end(rng), fun); + +#if BOOST_WORKAROUND(BOOST_MSVC, == 1600) + return for_each_detail::for_each_impl< + typename range_iterator::type, + UnaryFunction + >(boost::begin(rng), boost::end(rng), fun); +#else + return std::for_each< + BOOST_DEDUCED_TYPENAME range_iterator::type, + UnaryFunction + >(boost::begin(rng), boost::end(rng), fun); +#endif } } // namespace range using range::for_each; } // namespace boost -#endif // include guard +#endif // include guard \ No newline at end of file From d490a84c8d10b2232541cdec36f9631c181df4cc Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sat, 2 Apr 2011 10:14:51 +0000 Subject: [PATCH 02/14] [boost][range] - Improved the work-around for VC10 for_each implementation. Corrected a missing newline at the end of the file. [SVN r70850] --- include/boost/range/algorithm/for_each.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/range/algorithm/for_each.hpp b/include/boost/range/algorithm/for_each.hpp index dc2221d..12c9d4d 100755 --- a/include/boost/range/algorithm/for_each.hpp +++ b/include/boost/range/algorithm/for_each.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #if BOOST_WORKAROUND(BOOST_MSVC, == 1600) @@ -54,7 +55,7 @@ namespace boost void >::type* = 0) { - return std::for_each(first, last, fn); + return std::for_each(first, last, fn); } } #endif @@ -106,4 +107,4 @@ inline UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun) using range::for_each; } // namespace boost -#endif // include guard \ No newline at end of file +#endif // include guard From 126e6861d786f951ef1bc090d8eb98271b9e8faf Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sat, 2 Apr 2011 13:05:26 +0000 Subject: [PATCH 03/14] [boost][range] - Resolved Trace 5162 - boost::iterator_range is unsafe. [SVN r70852] --- include/boost/range/iterator_range_core.hpp | 4 ++-- test/Jamfile.v2 | 1 + test/compile_fail/iterator_range1.cpp | 21 +++++++++++++++++++++ test/iterator_range.cpp | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/compile_fail/iterator_range1.cpp diff --git a/include/boost/range/iterator_range_core.hpp b/include/boost/range/iterator_range_core.hpp index 438f38c..31d7147 100755 --- a/include/boost/range/iterator_range_core.hpp +++ b/include/boost/range/iterator_range_core.hpp @@ -53,13 +53,13 @@ namespace boost template< class ForwardRange > static IteratorT adl_begin( ForwardRange& r ) { - return IteratorT( boost::begin( r ) ); + return static_cast( boost::begin( r ) ); } template< class ForwardRange > static IteratorT adl_end( ForwardRange& r ) { - return IteratorT( boost::end( r ) ); + return static_cast( boost::end( r ) ); } }; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e0087fb..7086fd0 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,6 +31,7 @@ rule range-test ( name : includes * ) } test-suite range : + [ compile-fail compile_fail/iterator_range1.cpp ] [ range-test adaptor_test/adjacent_filtered ] [ range-test adaptor_test/copied ] [ range-test adaptor_test/filtered ] diff --git a/test/compile_fail/iterator_range1.cpp b/test/compile_fail/iterator_range1.cpp new file mode 100644 index 0000000..eed4ea9 --- /dev/null +++ b/test/compile_fail/iterator_range1.cpp @@ -0,0 +1,21 @@ +// Boost.Range library +// +// Copyright Neil Groves 2011. 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 +// + +#include + +namespace iterator_range_test_detail +{ + void check_iterator_range_doesnt_convert_pointers() + { + double source[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; + boost::iterator_range rng = boost::make_iterator_range(source); + } +} + diff --git a/test/iterator_range.cpp b/test/iterator_range.cpp index 8e9f380..1d9539b 100644 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -200,6 +200,15 @@ namespace iterator_range_test_detail } } } + + void check_iterator_range_from_array() + { + double source[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; + boost::iterator_range rng = boost::make_iterator_range(source); + BOOST_CHECK_EQUAL_COLLECTIONS( rng.begin(), rng.end(), + source, source + 6 ); + } + } // namespace iterator_range_test_detail template From df1a3a334f1dffe00411e9eeed5181794de9d583 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 11:16:53 +0000 Subject: [PATCH 04/14] [boost][range] - ticket 5544 - fix for termination of irange. [SVN r72070] --- include/boost/range/irange.hpp | 7 ++-- test/Jamfile.v2 | 1 + test/irange.cpp | 9 ++++- test/ticket_5544_terminate_irange.cpp | 47 +++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 test/ticket_5544_terminate_irange.cpp diff --git a/include/boost/range/irange.hpp b/include/boost/range/irange.hpp index 8045550..fe36e9d 100644 --- a/include/boost/range/irange.hpp +++ b/include/boost/range/irange.hpp @@ -216,9 +216,10 @@ namespace boost typedef typename range_detail::integer_iterator_with_step iterator_t; - const std::ptrdiff_t last_step - = (static_cast(last) - static_cast(first)) - / (static_cast(step_size)); + const std::ptrdiff_t l = static_cast(last); + const std::ptrdiff_t f = static_cast(first); + const std::ptrdiff_t sz = static_cast(step_size); + const std::ptrdiff_t last_step = (l + ((l-f) % sz) - f) / sz; return strided_integer_range( iterator_t(first, 0, step_size), diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7086fd0..f1fb3aa 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -156,5 +156,6 @@ test-suite range : [ range-test std_container ] [ range-test string ] [ range-test sub_range ] + [ range-test ticket_5544_terminate_irange ] ; diff --git a/test/irange.cpp b/test/irange.cpp index d71f184..985e07a 100644 --- a/test/irange.cpp +++ b/test/irange.cpp @@ -81,7 +81,6 @@ namespace boost void test_irange(int first, int last, int step_size) { BOOST_ASSERT( step_size != 0 ); - BOOST_ASSERT( (last - first) % step_size == 0 ); test_irange_impl(first, last, step_size); test_irange_impl(first, last, step_size); test_irange_impl(first, last, step_size); @@ -114,8 +113,16 @@ namespace boost test_irange(10, 0, -1); test_irange(0, 2, 2); test_irange(2, 0, -2); + test_irange(0, 9, 2); test_irange(10, 20, 5); test_irange(20, 10, -5); + + test_irange(0, 0, 3); + test_irange(0, 1, 3); + test_irange(0, 2, 3); + test_irange(0, 3, 3); + test_irange(0, 4, 3); + test_irange(0, 10, 3); } } // namespace boost diff --git a/test/ticket_5544_terminate_irange.cpp b/test/ticket_5544_terminate_irange.cpp new file mode 100644 index 0000000..fa64436 --- /dev/null +++ b/test/ticket_5544_terminate_irange.cpp @@ -0,0 +1,47 @@ +// Boost.Range library +// +// Copyright Neil Groves 2011. 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/ +// +#include +#include + +#include +#include + +#include + +namespace boost +{ + namespace + { + void test_irange_termination() + { + std::vector reference; + for (int i = 0; i < 9; i += 2) + reference.push_back(i); + + std::vector actual; + boost::push_back(actual, boost::irange(0,9,2)); + + BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(), + reference.begin(), reference.end()); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.ticket_5544" ); + + test->add( BOOST_TEST_CASE( &boost::test_irange_termination ) ); + + return test; +} From 5ed611649091a18b87abe375fe591bfc4747859c Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 19:59:59 +0000 Subject: [PATCH 05/14] [boost][range] - ticket 5544 - fix for termination of irange - done properly for negative step sizes. [SVN r72097] --- include/boost/range/irange.hpp | 19 +++++++------ test/irange.cpp | 49 ++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/include/boost/range/irange.hpp b/include/boost/range/irange.hpp index fe36e9d..3b5a6cc 100644 --- a/include/boost/range/irange.hpp +++ b/include/boost/range/irange.hpp @@ -124,13 +124,11 @@ namespace boost typedef typename base_t::difference_type difference_type; typedef typename base_t::reference reference; - integer_iterator_with_step(value_type first, value_type step, difference_type step_size) + integer_iterator_with_step(value_type first, difference_type step, value_type step_size) : m_first(first) , m_step(step) , m_step_size(step_size) { - BOOST_ASSERT( step >= 0 ); - BOOST_ASSERT( step_size != 0 ); } private: @@ -213,17 +211,18 @@ namespace boost { BOOST_ASSERT( step_size != 0 ); BOOST_ASSERT( (step_size > 0) ? (last >= first) : (last <= first) ); - + typedef typename range_detail::integer_iterator_with_step iterator_t; - const std::ptrdiff_t l = static_cast(last); - const std::ptrdiff_t f = static_cast(first); - const std::ptrdiff_t sz = static_cast(step_size); - const std::ptrdiff_t last_step = (l + ((l-f) % sz) - f) / sz; - + const std::ptrdiff_t sz = static_cast(step_size >= 0 ? step_size : -step_size); + const Integer l = step_size >= 0 ? last : first; + const Integer f = step_size >= 0 ? first : last; + const std::ptrdiff_t num_steps = (l + ((l-f) % sz) - f) / sz; + BOOST_ASSERT(num_steps >= 0); + return strided_integer_range( iterator_t(first, 0, step_size), - iterator_t(first, last_step, step_size)); + iterator_t(first, num_steps, step_size)); } } // namespace boost diff --git a/test/irange.cpp b/test/irange.cpp index 985e07a..358a2b1 100644 --- a/test/irange.cpp +++ b/test/irange.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include namespace boost @@ -35,27 +34,38 @@ namespace boost BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(), reference.begin(), reference.end() ); } + + template + std::ptrdiff_t test_irange_calculate_num_steps(Integer first, Integer last, int step) + { + const std::ptrdiff_t sz = static_cast(step >= 0 ? step : -step); + const std::ptrdiff_t l = static_cast(step >= 0 ? last : first); + const std::ptrdiff_t f = static_cast(step >= 0 ? first : last); + return (l + ((l-f) % sz) - f) / sz; + } // Test an integer range with a runtime specified step size. - template - void test_irange_impl(Integer first, Integer last, int step) + template + void test_irange_impl(IntegerInput first, IntegerInput last, int step) { BOOST_ASSERT( step != 0 ); + + // Skip tests that have negative values if the type is + // unsigned + if ((static_cast(static_cast(first)) != first) + || (static_cast(static_cast(last)) != last)) + return; + std::vector reference; - if (step > 0) - { - for (Integer i = first; i < last; i += step) - reference.push_back(i); - } - else - { - for (Integer i = first; i > last; i += step) - reference.push_back(i); - } + + const std::ptrdiff_t num_steps = test_irange_calculate_num_steps(first, last, step); + Integer current_value = first; + for (std::ptrdiff_t i = 0; i < num_steps; ++i, current_value += step) + reference.push_back(current_value); std::vector test; boost::push_back(test, boost::irange(first, last, step)); - + BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(), reference.begin(), reference.end() ); } @@ -114,6 +124,10 @@ namespace boost test_irange(0, 2, 2); test_irange(2, 0, -2); test_irange(0, 9, 2); + test_irange(9, 0, -2); + test_irange(-9, 0, 2); + test_irange(-9, 9, 2); + test_irange(9, -9, -2); test_irange(10, 20, 5); test_irange(20, 10, -5); @@ -123,6 +137,13 @@ namespace boost test_irange(0, 3, 3); test_irange(0, 4, 3); test_irange(0, 10, 3); + + test_irange(0, 0, -3); + test_irange(0, -1, -3); + test_irange(0, -2, -3); + test_irange(0, -3, -3); + test_irange(0, -4, -3); + test_irange(0, -10, -3); } } // namespace boost From 3b3889b70f07ccd082591543d25bcbb4e17a3ead Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 20:01:12 +0000 Subject: [PATCH 06/14] [boost][range] - Ticket 5485 - doubly defined BOOST_DEFINE_RANGE_ADAPTOR_1 macro. [SVN r72098] --- include/boost/range/adaptor/define_adaptor.hpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/include/boost/range/adaptor/define_adaptor.hpp b/include/boost/range/adaptor/define_adaptor.hpp index 26f4016..b228df3 100644 --- a/include/boost/range/adaptor/define_adaptor.hpp +++ b/include/boost/range/adaptor/define_adaptor.hpp @@ -44,24 +44,6 @@ return range_adaptor (rng); \ } -#define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, adaptor_class ) \ - template range_adaptor \ - operator|(Range& rng, const adaptor_name & args) \ - { \ - return range_adaptor (rng, args.arg1); \ - } \ - template range_adaptor \ - operator|(const Range& rng, const adaptor_name & args) \ - { \ - return range_adaptor (rng, args.arg1); \ - } \ - template \ - range_adaptor \ - make_##adaptor_name(Range& rng, Arg1 arg1) \ - { \ - return range_adaptor(rng, arg1); \ - } - #define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, arg1_type ) \ struct adaptor_name \ { \ From b06fca837865b3aefa2f4f785629e76bfde643b0 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 20:20:20 +0000 Subject: [PATCH 07/14] [boost][range] - Ticket 5556 - is_sorted namespace issue under GCC 4.5 [SVN r72101] --- test/Jamfile.v2 | 1 + test/ticket_5556_is_sorted_namespace.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/ticket_5556_is_sorted_namespace.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f1fb3aa..ba8a08a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -157,5 +157,6 @@ test-suite range : [ range-test string ] [ range-test sub_range ] [ range-test ticket_5544_terminate_irange ] + [ range-test ticket_5556_is_sorted_namespace ] ; diff --git a/test/ticket_5556_is_sorted_namespace.cpp b/test/ticket_5556_is_sorted_namespace.cpp new file mode 100644 index 0000000..78a75cd --- /dev/null +++ b/test/ticket_5556_is_sorted_namespace.cpp @@ -0,0 +1,37 @@ +// Boost.Range library +// +// Copyright Neil Groves 2011. 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/ +// + +// Embarrasingly, the mere inclusion of these headers in this order was +// enough to trigger the defect. +#include +#include + +#include +#include + +namespace boost +{ + namespace + { + void test_ticket_5556() {} + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.ticket_5556" ); + + test->add( BOOST_TEST_CASE( &boost::test_ticket_5556 ) ); + + return test; +} From 44c26a3356ac9293570b30383ebfd4abf2c980f7 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 20:33:06 +0000 Subject: [PATCH 08/14] [boost][range] - Ticket 5486 - Removal of unnecessary variables from adjacent_filtered_range. This removes the requirement for the predicate to be default constructible. [SVN r72102] --- .../boost/range/adaptor/adjacent_filtered.hpp | 4 -- test/Jamfile.v2 | 1 + test/ticket_5486.cpp | 56 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/ticket_5486.cpp diff --git a/include/boost/range/adaptor/adjacent_filtered.hpp b/include/boost/range/adaptor/adjacent_filtered.hpp index edc1dff..f717cb3 100644 --- a/include/boost/range/adaptor/adjacent_filtered.hpp +++ b/include/boost/range/adaptor/adjacent_filtered.hpp @@ -143,10 +143,6 @@ namespace boost skip_iter(boost::end(r), boost::end(r), p)) { } - - private: - P m_pred; - R* m_range; }; template< class T > diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ba8a08a..4845d4e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -156,6 +156,7 @@ test-suite range : [ range-test std_container ] [ range-test string ] [ range-test sub_range ] + [ range-test ticket_5486 ] [ range-test ticket_5544_terminate_irange ] [ range-test ticket_5556_is_sorted_namespace ] ; diff --git a/test/ticket_5486.cpp b/test/ticket_5486.cpp new file mode 100644 index 0000000..3a6bf4b --- /dev/null +++ b/test/ticket_5486.cpp @@ -0,0 +1,56 @@ +// Boost.Range library +// +// Copyright Neil Groves 2011. 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/ +// +#include +#include + +#include +#include + +#include +#include + +namespace boost +{ + namespace + { + class TestTicket5486Pred + : public std::binary_function + { + public: + explicit TestTicket5486Pred(int x) {} + bool operator()(int,int) const { return true; } + private: + TestTicket5486Pred(); + }; + + // Ticket 5486 - pertained to predicates erroneous + // requiring default construction + void test_ticket_5486() + { + std::vector v; + boost::push_back(v, v | boost::adaptors::adjacent_filtered(TestTicket5486Pred(1))); + + BOOST_CHECK_EQUAL_COLLECTIONS( v.begin(), v.end(), + v.begin(), v.end() ); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.ticket_5486" ); + + test->add( BOOST_TEST_CASE( &boost::test_ticket_5486 ) ); + + return test; +} From 91428c211093d74a2525f277b53f20f0c224c187 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 21:03:01 +0000 Subject: [PATCH 09/14] [boost][range] - Ticket 5530 - adaptor example fails to compile. This change adds tests for all of the .cpp example files for the range adaptors, and fixes a few small issues with the examples shown by the new tests. [SVN r72104] --- .../adaptors/examples/adjacent_filtered.cpp | 2 +- doc/reference/adaptors/examples/indexed.cpp | 2 +- doc/reference/adaptors/examples/transformed.cpp | 2 +- test/Jamfile.v2 | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/reference/adaptors/examples/adjacent_filtered.cpp b/doc/reference/adaptors/examples/adjacent_filtered.cpp index 7830a1d..cc7cd9b 100644 --- a/doc/reference/adaptors/examples/adjacent_filtered.cpp +++ b/doc/reference/adaptors/examples/adjacent_filtered.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/doc/reference/adaptors/examples/indexed.cpp b/doc/reference/adaptors/examples/indexed.cpp index 3178457..bb141e8 100644 --- a/doc/reference/adaptors/examples/indexed.cpp +++ b/doc/reference/adaptors/examples/indexed.cpp @@ -41,5 +41,5 @@ int main(int argc, const char* argv[]) display_element_and_index( input | indexed(0) ); return 0; -] +} diff --git a/doc/reference/adaptors/examples/transformed.cpp b/doc/reference/adaptors/examples/transformed.cpp index f2a46f5..62bf5d4 100644 --- a/doc/reference/adaptors/examples/transformed.cpp +++ b/doc/reference/adaptors/examples/transformed.cpp @@ -9,7 +9,7 @@ // #include #include -#include +#include #include #include #include diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4845d4e..ec67d7b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,6 +31,21 @@ rule range-test ( name : includes * ) } test-suite range : + [ compile ../doc/reference/adaptors/examples/adjacent_filtered.cpp : : example_adjacent_filtered ] + [ compile ../doc/reference/adaptors/examples/copied.cpp : : example_copied ] + [ compile ../doc/reference/adaptors/examples/filtered.cpp : : example_filtered ] + [ compile ../doc/reference/adaptors/examples/indexed.cpp : : example_indexed ] + [ compile ../doc/reference/adaptors/examples/indirected.cpp : : example_indirected ] + [ compile ../doc/reference/adaptors/examples/map_keys.cpp : : example_map_keys ] + [ compile ../doc/reference/adaptors/examples/map_values.cpp : : example_map_values ] + [ compile ../doc/reference/adaptors/examples/replaced.cpp : : example_replaced ] + [ compile ../doc/reference/adaptors/examples/replaced_if.cpp : : example_replaced_if ] + [ compile ../doc/reference/adaptors/examples/reversed.cpp : : example_reversed ] + [ compile ../doc/reference/adaptors/examples/sliced.cpp : : example_sliced ] + [ compile ../doc/reference/adaptors/examples/strided.cpp : : example_strided ] + [ compile ../doc/reference/adaptors/examples/tokenized.cpp : : example_tokenized ] + [ compile ../doc/reference/adaptors/examples/transformed.cpp : : example_transformed ] + [ compile ../doc/reference/adaptors/examples/uniqued.cpp : : example_uniqued ] [ compile-fail compile_fail/iterator_range1.cpp ] [ range-test adaptor_test/adjacent_filtered ] [ range-test adaptor_test/copied ] From 8810c4c4aae24f36cba1f019753ac214d6f24461 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 21:19:53 +0000 Subject: [PATCH 10/14] [boost][range] - Ticket 5547 - Boost.Range join() ambiguous with Boost.Algorithm join() function. Put the Boost.Range join function into the boost::range namespace and brought out with 'using' [SVN r72106] --- include/boost/range/join.hpp | 8 +++++++ test/Jamfile.v2 | 1 + test/ticket_5547.cpp | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 test/ticket_5547.cpp diff --git a/include/boost/range/join.hpp b/include/boost/range/join.hpp index ad0217e..aacc0a3 100644 --- a/include/boost/range/join.hpp +++ b/include/boost/range/join.hpp @@ -36,6 +36,9 @@ public: } // namespace range_detail +namespace range +{ + template class joined_range : public range_detail::joined_type::type @@ -78,6 +81,11 @@ join(SinglePassRange1& r1, SinglePassRange2& r2) return joined_range(r1, r2); } +} // namespace range + +using ::boost::range::joined_range; +using ::boost::range::join; + } // namespace boost #endif // include guard diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ec67d7b..afab584 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -173,6 +173,7 @@ test-suite range : [ range-test sub_range ] [ range-test ticket_5486 ] [ range-test ticket_5544_terminate_irange ] + [ range-test ticket_5547 ] [ range-test ticket_5556_is_sorted_namespace ] ; diff --git a/test/ticket_5547.cpp b/test/ticket_5547.cpp new file mode 100644 index 0000000..1b9d3f6 --- /dev/null +++ b/test/ticket_5547.cpp @@ -0,0 +1,42 @@ +// Boost.Range library +// +// Copyright Neil Groves 2011. 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/ +// +#include +#include + +#include +#include + +#include + +namespace boost +{ + namespace + { + + // Ticket 5547 - boost::join ambiguous with algorithm::join + void test_ticket_5547() + { + std::vector x; + boost::range::join(x,x); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.ticket_5547" ); + + test->add( BOOST_TEST_CASE( &boost::test_ticket_5547 ) ); + + return test; +} From 846f11a96cd8623cdbd74d96b2ff0ca2f1aa1cfd Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 22:06:30 +0000 Subject: [PATCH 11/14] [boost][range] - Ticket 5236 - Strided reversing past begin issue resolved. [SVN r72107] --- include/boost/range/adaptor/strided.hpp | 43 ++++++++++++------------- test/adaptor_test/strided.cpp | 20 ++++++++++++ 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/include/boost/range/adaptor/strided.hpp b/include/boost/range/adaptor/strided.hpp index abfad5e..e843f62 100755 --- a/include/boost/range/adaptor/strided.hpp +++ b/include/boost/range/adaptor/strided.hpp @@ -176,6 +176,7 @@ namespace boost strided_iterator() : m_first() , m_last() + , m_index(0) , m_stride() { } @@ -184,6 +185,7 @@ namespace boost : super_t(it) , m_first(first) , m_last(last) + , m_index(stride ? (it - first) / stride : 0) , m_stride(stride) { } @@ -194,6 +196,7 @@ namespace boost : super_t(other.base()) , m_first(other.base_begin()) , m_last(other.base_end()) + , m_index(other.get_index()) , m_stride(other.get_stride()) { } @@ -201,44 +204,37 @@ namespace boost base_iterator base_begin() const { return m_first; } base_iterator base_end() const { return m_last; } difference_type get_stride() const { return m_stride; } + difference_type get_index() const { return m_index; } private: void increment() { - base_iterator& it = this->base_reference(); - if ((m_last - it) > m_stride) - it += m_stride; + m_index += m_stride; + if (m_index < (m_last - m_first)) + this->base_reference() = m_first + m_index; else - it = m_last; + this->base_reference() = m_last; } void decrement() { - base_iterator& it = this->base_reference(); - if ((it - m_first) > m_stride) - it -= m_stride; + m_index -= m_stride; + if (m_index >= 0) + this->base_reference() = m_first + m_index; else - it = m_first; + this->base_reference() = m_first; } void advance(difference_type offset) { - base_iterator& it = this->base_reference(); offset *= m_stride; - if (offset >= 0) - { - if ((m_last - it) > offset) - it += offset; - else - it = m_last; - } + m_index += offset; + if (m_index < 0) + this->base_reference() = m_first; + else if (m_index > (m_last - m_first)) + this->base_reference() = m_last; else - { - if ((m_first - it) > offset) - it += offset; - else - it = m_first; - } + this->base_reference() = m_first + m_index; } template @@ -252,12 +248,13 @@ namespace boost bool equal(const strided_iterator& other) const { - return other.base() == this->base(); + return this->base() == other.base(); } private: base_iterator m_first; base_iterator m_last; + difference_type m_index; difference_type m_stride; }; diff --git a/test/adaptor_test/strided.cpp b/test/adaptor_test/strided.cpp index 91beb81..6389a30 100644 --- a/test/adaptor_test/strided.cpp +++ b/test/adaptor_test/strided.cpp @@ -250,6 +250,25 @@ namespace boost BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), output.begin(), output.end() ); } + + template + void strided_test_ticket_5236_check(const Range& rng) + { + BOOST_CHECK_EQUAL( boost::distance(rng), 1 ); + BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), boost::prior(boost::end(rng))), 0 ); + + typename boost::range_iterator::type it = boost::end(rng); + it = it - 1; + + BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), it), 0 ); + } + + void strided_test_ticket_5236() + { + std::vector v; + v.push_back(1); + strided_test_ticket_5236_check( v | boost::adaptors::strided(2) ); + } } } @@ -262,6 +281,7 @@ init_unit_test_suite(int argc, char* argv[]) test->add( BOOST_TEST_CASE( &boost::strided_test ) ); test->add( BOOST_TEST_CASE( &boost::strided_defect_Trac5014 ) ); test->add( BOOST_TEST_CASE( &boost::strided_test_traversal ) ); + test->add( BOOST_TEST_CASE( &boost::strided_test_ticket_5236 ) ); return test; } From 41b76f8f5c99237c53e5631e8a4d5154ebd169d7 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 22:15:14 +0000 Subject: [PATCH 12/14] [boost][range] - Ticket 5236 - Improved test coverage to ensure that the result for a random access strided range is consistent with that of a bidirectional strided range. [SVN r72108] --- test/adaptor_test/strided.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/adaptor_test/strided.cpp b/test/adaptor_test/strided.cpp index 6389a30..1198a10 100644 --- a/test/adaptor_test/strided.cpp +++ b/test/adaptor_test/strided.cpp @@ -252,14 +252,19 @@ namespace boost } template - void strided_test_ticket_5236_check(const Range& rng) + void strided_test_ticket_5236_check_bidirectional(const Range& rng) { BOOST_CHECK_EQUAL( boost::distance(rng), 1 ); BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), boost::prior(boost::end(rng))), 0 ); - + } + + template + void strided_test_ticket_5236_check(const Range& rng) + { + strided_test_ticket_5236_check_bidirectional(rng); + typename boost::range_iterator::type it = boost::end(rng); it = it - 1; - BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), it), 0 ); } @@ -268,7 +273,15 @@ namespace boost std::vector v; v.push_back(1); strided_test_ticket_5236_check( v | boost::adaptors::strided(2) ); + + // Ensure that there is consistency between the random-access implementation + // and the bidirectional. + + std::list l; + l.push_back(1); + strided_test_ticket_5236_check_bidirectional( l | boost::adaptors::strided(2) ); } + } } From c4bd4bf4ce4a4ce0d2dcd44908266d04fde60921 Mon Sep 17 00:00:00 2001 From: Bryce Adelstein-Lelbach Date: Thu, 26 May 2011 18:23:57 +0000 Subject: [PATCH 13/14] Remove tabs. [SVN r72190] --- include/boost/range/iterator_range_core.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 include/boost/range/iterator_range_core.hpp diff --git a/include/boost/range/iterator_range_core.hpp b/include/boost/range/iterator_range_core.hpp old mode 100755 new mode 100644 index 31d7147..60c7670 --- a/include/boost/range/iterator_range_core.hpp +++ b/include/boost/range/iterator_range_core.hpp @@ -249,7 +249,7 @@ namespace boost difference_type size() const { - return m_End - m_Begin; + return m_End - m_Begin; } bool empty() const From 1cb6a99c80d86b76735753f163ac98448375b30f Mon Sep 17 00:00:00 2001 From: Gennadiy Rozental Date: Wed, 5 Oct 2011 09:13:05 +0000 Subject: [PATCH 14/14] eliminated unit_test_framework [SVN r74719] --- test/adl_conformance.cpp | 4 ++-- test/begin.cpp | 8 ++++---- test/compat2.cpp | 4 ++-- test/compat3.cpp | 4 ++-- test/end.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) mode change 100755 => 100644 test/compat3.cpp diff --git a/test/adl_conformance.cpp b/test/adl_conformance.cpp index 2d7f290..277c183 100644 --- a/test/adl_conformance.cpp +++ b/test/adl_conformance.cpp @@ -172,9 +172,9 @@ void check_adl_conformance() BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace ); } -#include +#include -using boost::unit_test_framework::test_suite; +using boost::unit_test::test_suite; test_suite* init_unit_test_suite( int argc, char* argv[] ) { diff --git a/test/begin.cpp b/test/begin.cpp index eb745c2..bbc11c1 100644 --- a/test/begin.cpp +++ b/test/begin.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace mock_std { @@ -104,12 +104,12 @@ namespace } } -using boost::unit_test_framework::test_suite; +using boost::unit_test::test_suite; -boost::unit_test_framework::test_suite* +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - begin() ADL namespace barrier" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - begin() ADL namespace barrier" ); test->add( BOOST_TEST_CASE( &test_range_begin ) ); diff --git a/test/compat2.cpp b/test/compat2.cpp index 1a5359c..2874c04 100644 --- a/test/compat2.cpp +++ b/test/compat2.cpp @@ -53,9 +53,9 @@ void compat1() iterator_of< std::vector >::type i = v.begin(); } -#include +#include -using boost::unit_test_framework::test_suite; +using boost::unit_test::test_suite; test_suite* init_unit_test_suite( int argc, char* argv[] ) { diff --git a/test/compat3.cpp b/test/compat3.cpp old mode 100755 new mode 100644 index 00987e4..5249c58 --- a/test/compat3.cpp +++ b/test/compat3.cpp @@ -53,9 +53,9 @@ void compat1() iterator_of< std::vector >::type i = v.begin(); } -#include +#include -using boost::unit_test_framework::test_suite; +using boost::unit_test::test_suite; test_suite* init_unit_test_suite( int argc, char* argv[] ) { diff --git a/test/end.cpp b/test/end.cpp index e3383c3..3e989ff 100644 --- a/test/end.cpp +++ b/test/end.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace mock_std { @@ -104,12 +104,12 @@ namespace } } -using boost::unit_test_framework::test_suite; +using boost::unit_test::test_suite; -boost::unit_test_framework::test_suite* +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - boost::unit_test_framework::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - end() ADL namespace barrier" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - end() ADL namespace barrier" ); test->add( BOOST_TEST_CASE( &test_range_end_adl_avoidance ) );