From df1a3a334f1dffe00411e9eeed5181794de9d583 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 22 May 2011 11:16:53 +0000 Subject: [PATCH 01/41] [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 02/41] [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 03/41] [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 04/41] [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 05/41] [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 06/41] [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 07/41] [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 08/41] [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 09/41] [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 10/41] 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 11/41] 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 ) ); From 11238e4c19537aa12c9a110f60863f05619723ab Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 15 Apr 2012 11:52:01 +0000 Subject: [PATCH 12/41] [boost][range] - Trac 5971 - size() should return an unsigned type. [SVN r77990] --- doc/mfc_atl.qbk | 2 +- doc/portability.qbk | 2 +- doc/reference/semantics.qbk | 2 +- doc/reference/synopsis.qbk | 28 ++++---- doc/reference/utilities.qbk | 74 ++++++++++---------- doc/style.qbk | 8 +-- doc/upgrade.qbk | 6 ++ include/boost/range/algorithm/equal.hpp | 20 ++++-- include/boost/range/algorithm_ext/copy_n.hpp | 8 +-- include/boost/range/detail/size_type.hpp | 41 ++++------- include/boost/range/size.hpp | 6 +- include/boost/range/size_type.hpp | 60 +++++++++------- test/algorithm_test/for_each.cpp | 2 +- test/extension_size.cpp | 2 +- 14 files changed, 136 insertions(+), 125 deletions(-) mode change 100755 => 100644 include/boost/range/algorithm/equal.hpp mode change 100755 => 100644 include/boost/range/algorithm_ext/copy_n.hpp mode change 100755 => 100644 include/boost/range/detail/size_type.hpp diff --git a/doc/mfc_atl.qbk b/doc/mfc_atl.qbk index 0511509..de2e225 100644 --- a/doc/mfc_atl.qbk +++ b/doc/mfc_atl.qbk @@ -41,7 +41,7 @@ BOOST_FOREACH (CList *theList, myArray) * Boost C++ Libraries Version 1.34.0 or later (no compilation required) * Visual C++ 7.1 or later (for MFC and ATL) - + [endsect] [section:mfc_ranges MFC Ranges] diff --git a/doc/portability.qbk b/doc/portability.qbk index aed3825..fabaafc 100644 --- a/doc/portability.qbk +++ b/doc/portability.qbk @@ -19,7 +19,7 @@ For maximum portability you should follow these guidelines: # use __const_begin__`()` and __const_end__`()` whenever your code by intention is read-only; this will also solve most rvalue problems, # do not rely on ADL: * if you overload functions, include that header before the headers in this library, - * put all overloads in namespace boost. + * put all overloads in namespace boost. diff --git a/doc/reference/semantics.qbk b/doc/reference/semantics.qbk index 335ab90..0710a99 100644 --- a/doc/reference/semantics.qbk +++ b/doc/reference/semantics.qbk @@ -128,7 +128,7 @@ ] [ [`size(x)`] - [`range_difference::type`] + [`range_size::type`] [`range_calculate_size(x)` which by default is `boost::end(x) - boost::begin(x)`. Users may supply alternative implementations by implementing `range_calculate_size(x)` so that it will be found via ADL] [constant time] ] diff --git a/doc/reference/synopsis.qbk b/doc/reference/synopsis.qbk index 381d77b..76719df 100644 --- a/doc/reference/synopsis.qbk +++ b/doc/reference/synopsis.qbk @@ -20,10 +20,10 @@ namespace boost template< class T > struct range_reference; - + template< class T > struct range_pointer; - + template< class T > struct range_category; @@ -92,11 +92,11 @@ namespace boost template< class T > typename range_reverse_iterator::type rend( const T& r ); - + // // Random Access Range functions // - + template< class T > typename range_difference::type size( const T& r ); @@ -106,42 +106,42 @@ namespace boost // template< class T > - typename range_iterator::type + typename range_iterator::type const_begin( const T& r ); template< class T > - typename range_iterator::type + typename range_iterator::type const_end( const T& r ); template< class T > - typename range_reverse_iterator::type + typename range_reverse_iterator::type const_rbegin( const T& r ); template< class T > - typename range_reverse_iterator::type + typename range_reverse_iterator::type const_rend( const T& r ); - + // // String utilities // - + template< class T > iterator_range< ... see below ... > as_literal( T& r ); - + template< class T > iterator_range< ... see below ... > as_literal( const T& r ); - + template< class T > iterator_range< typename range_iterator::type > as_array( T& r ); - + template< class T > iterator_range< typename range_iterator::type > as_array( const T& r ); -} // namespace 'boost' +} // namespace 'boost' `` [endsect] diff --git a/doc/reference/utilities.qbk b/doc/reference/utilities.qbk index 94d4699..25a7edb 100644 --- a/doc/reference/utilities.qbk +++ b/doc/reference/utilities.qbk @@ -40,23 +40,23 @@ namespace boost public: // construction, assignment template< class ForwardTraversalIterator2 > iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); - + template< class ForwardRange > iterator_range( ForwardRange& r ); - + template< class ForwardRange > iterator_range( const ForwardRange& r ); - + template< class ForwardRange > iterator_range& operator=( ForwardRange& r ); template< class ForwardRange > iterator_range& operator=( const ForwardRange& r ); - + public: // Forward Range functions iterator begin() const; iterator end() const; - + public: // convenience operator unspecified_bool_type() const; bool equal( const iterator_range& ) const; @@ -65,25 +65,25 @@ namespace boost iterator_range& advance_begin(difference_type n); iterator_range& advance_end(difference_type n); bool empty() const; - // for Random Access Range only: + // for Random Access Range only: reference operator[]( difference_type at ) const; value_type operator()( difference_type at ) const; size_type size() const; }; - + // stream output template< class ForwardTraversalIterator, class T, class Traits > - std::basic_ostream& + std::basic_ostream& operator<<( std::basic_ostream& Os, const iterator_range& r ); // comparison template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator==( const iterator_range& l, + bool operator==( const iterator_range& l, const iterator_range& r ); template< class ForwardTraversalIterator, class ForwardRange > - bool operator==( const iterator_range& l, + bool operator==( const iterator_range& l, const ForwardRange& r ); template< class ForwardTraversalIterator, class ForwardRange > @@ -91,11 +91,11 @@ namespace boost const iterator_range& r ); template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator!=( const iterator_range& l, + bool operator!=( const iterator_range& l, const iterator_range& r ); template< class ForwardTraversalIterator, class ForwardRange > - bool operator!=( const iterator_range& l, + bool operator!=( const iterator_range& l, const ForwardRange& r ); template< class ForwardTraversalIterator, class ForwardRange > @@ -103,23 +103,23 @@ namespace boost const iterator_range& r ); template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator<( const iterator_range& l, + bool operator<( const iterator_range& l, const iterator_range& r ); template< class ForwardTraversalIterator, class ForwardRange > - bool operator<( const iterator_range& l, + bool operator<( const iterator_range& l, const ForwardRange& r ); template< class ForwardTraversalIterator, class ForwardRange > bool operator<( const ForwardRange& l, const iterator_range& r ); - + // external construction template< class ForwardTraversalIterator > iterator_range< ForwardTraversalIterator > - make_iterator_range( ForwardTraversalIterator Begin, + make_iterator_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); - + template< class ForwardRange > iterator_range< typename range_iterator::type > make_iterator_range( ForwardRange& r ); @@ -127,25 +127,25 @@ namespace boost template< class ForwardRange > iterator_range< typename range_iterator::type > make_iterator_range( const ForwardRange& r ); - + template< class Range > iterator_range< typename range_iterator::type > make_iterator_range( Range& r, typename range_difference::type advance_begin, typename range_difference::type advance_end ); - + template< class Range > iterator_range< typename range_iterator::type > - make_iterator_range( const Range& r, + make_iterator_range( const Range& r, typename range_difference::type advance_begin, typename range_difference::type advance_end ); - + // convenience template< class Sequence, class ForwardRange > Sequence copy_range( const ForwardRange& r ); - + } // namespace 'boost' -`` +`` If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end). @@ -177,7 +177,7 @@ It is worth noticing that the templated constructors and assignment operators al `` iterator_range make_iterator_range( Range& r, - typename range_difference::type advance_begin, + typename range_difference::type advance_begin, typename range_difference::type advance_end ); `` @@ -209,46 +209,46 @@ namespace boost template< class ForwardRange > class sub_range : public iterator_range< typename range_iterator::type > { - public: + public: typedef typename range_iterator::type iterator; typedef typename range_iterator::type const_iterator; typedef typename iterator_difference::type difference_type; - + public: // construction, assignment template< class ForwardTraversalIterator > sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); template< class ForwardRange2 > sub_range( ForwardRange2& r ); - + template< class ForwardRange2 > sub_range( const Range2& r ); - + template< class ForwardRange2 > sub_range& operator=( ForwardRange2& r ); template< class ForwardRange2 > - sub_range& operator=( const ForwardRange2& r ); - - public: // Forward Range functions + sub_range& operator=( const ForwardRange2& r ); + + public: // Forward Range functions iterator begin(); const_iterator begin() const; iterator end(); - const_iterator end() const; - - public: // convenience + const_iterator end() const; + + public: // convenience value_type& front(); const value_type& front() const; value_type& back(); const value_type& back() const; - // for Random Access Range only: + // for Random Access Range only: value_type& operator[]( size_type at ); const value_type& operator[]( size_type at ) const; - + public: // rest of interface inherited from iterator_range }; - + } // namespace 'boost' `` diff --git a/doc/style.qbk b/doc/style.qbk index c6e5e34..2074ba6 100644 --- a/doc/style.qbk +++ b/doc/style.qbk @@ -13,7 +13,7 @@ Since ranges are characterized by a specific underlying iterator type, we get a * Readable Range * Writeable Range * Swappable Range - * Lvalue Range + * Lvalue Range * [*/Traversal/] category: * __single_pass_range__ * __forward_range__ @@ -25,7 +25,7 @@ Notice how we have used the categories from the __new_style_iterators__. Notice that an iterator (and therefore an range) has one [*/traversal/] property and one or more properties from the [*/value access/] category. So in reality we will mostly talk about mixtures such as * Random Access Readable Writeable Range -* Forward Lvalue Range +* Forward Lvalue Range By convention, we should always specify the [*/traversal/] property first as done above. This seems reasonable since there will only be one [*/traversal/] property, but perhaps many [*/value access/] properties. @@ -37,7 +37,7 @@ As another example, consider how we specify the interface of `std::sort()`. Algo template< class RandomAccessTraversalReadableWritableIterator > void sort( RandomAccessTraversalReadableWritableIterator first, RandomAccessTraversalReadableWritableIterator last ); -`` +`` For ranges the interface becomes @@ -45,6 +45,6 @@ For ranges the interface becomes template< class RandomAccessReadableWritableRange > void sort( RandomAccessReadableWritableRange& r ); `` - + [endsect] diff --git a/doc/upgrade.qbk b/doc/upgrade.qbk index 516ed11..e97f761 100644 --- a/doc/upgrade.qbk +++ b/doc/upgrade.qbk @@ -5,6 +5,12 @@ /] [section:upgrade Upgrade version of Boost.Range] +[section:upgrade_from_1_49 Upgrade from version 1.49] + +# __size__ now returns the type Rng::size_type if the range has size_type; +otherwise range_size::type is used. This is the distance type promoted to +an unsigned type. + [section:upgrade_from_1_45 Upgrade from version 1.45] # __size__ in addition to supporting __random_access_range__ now also supports extensibility via calls to the unqualified `range_calculate_size(rng)` function. diff --git a/include/boost/range/algorithm/equal.hpp b/include/boost/range/algorithm/equal.hpp old mode 100755 new mode 100644 index a3ebc29..4472bb1 --- a/include/boost/range/algorithm/equal.hpp +++ b/include/boost/range/algorithm/equal.hpp @@ -31,7 +31,7 @@ namespace boost IteratorCategoryTag1, IteratorCategoryTag2 ) { - do + while (true) { // If we have reached the end of the left range then this is // the end of the loop. They are equal if and only if we have @@ -46,7 +46,12 @@ namespace boost return false; // continue looping if and only if the values are equal - } while(*first1++ == *first2++); + if (*first1 != *first2) + break; + + ++first1; + ++first2; + } // Reaching this line in the algorithm indicates that a value // inequality has been detected. @@ -66,7 +71,7 @@ namespace boost IteratorCategoryTag1, IteratorCategoryTag2 ) { - do + while (true) { // If we have reached the end of the left range then this is // the end of the loop. They are equal if and only if we have @@ -81,7 +86,12 @@ namespace boost return false; // continue looping if and only if the values are equal - } while(pred(*first1++, *first2++)); + if (!pred(*first1, *first2)) + break; + + ++first1; + ++first2; + } // Reaching this line in the algorithm indicates that a value // inequality has been detected. @@ -182,7 +192,7 @@ namespace boost } } // namespace range - using range::equal; + using ::boost::range::equal; } // namespace boost #endif // include guard diff --git a/include/boost/range/algorithm_ext/copy_n.hpp b/include/boost/range/algorithm_ext/copy_n.hpp old mode 100755 new mode 100644 index ba7ad1c..f855441 --- a/include/boost/range/algorithm_ext/copy_n.hpp +++ b/include/boost/range/algorithm_ext/copy_n.hpp @@ -30,15 +30,15 @@ namespace boost /// /// \pre SinglePassRange is a model of the SinglePassRangeConcept /// \pre OutputIterator is a model of the OutputIteratorConcept -/// \pre 0 <= n < distance(rng) +/// \pre 0 <= n <= distance(rng) template< class SinglePassRange, class Size, class OutputIterator > inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out) { BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); - BOOST_ASSERT( n < static_cast(boost::distance(rng)) ); + BOOST_ASSERT( n <= static_cast(::boost::distance(rng)) ); BOOST_ASSERT( n >= static_cast(0) ); - BOOST_DEDUCED_TYPENAME range_iterator::type source = boost::begin(rng); + BOOST_DEDUCED_TYPENAME range_iterator::type source = ::boost::begin(rng); for (Size i = 0; i < n; ++i, ++out, ++source) *out = *source; @@ -47,7 +47,7 @@ inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator } } // namespace range - using range::copy_n; + using ::boost::range::copy_n; } // namespace boost #endif // include guard diff --git a/include/boost/range/detail/size_type.hpp b/include/boost/range/detail/size_type.hpp old mode 100755 new mode 100644 index ec49f4d..78a60a4 --- a/include/boost/range/detail/size_type.hpp +++ b/include/boost/range/detail/size_type.hpp @@ -17,12 +17,19 @@ // missing partial specialization workaround. ////////////////////////////////////////////////////////////////////////////// -namespace boost +namespace boost { - namespace range_detail - { + namespace range_detail + { template< typename T > - struct range_size_type_; + struct range_size_type_ + { + template< typename C > + struct pts + { + typedef std::size_t type; + }; + }; template<> struct range_size_type_ @@ -33,36 +40,14 @@ namespace boost typedef BOOST_RANGE_DEDUCED_TYPENAME C::size_type type; }; }; + } - template<> - struct range_size_type_ - { - template< typename P > - struct pts - { - typedef std::size_t type; - }; - }; - - template<> - struct range_size_type_ - { - template< typename A > - struct pts - { - typedef std::size_t type; - }; - }; - - - } - template< typename C > class range_size { typedef typename range_detail::range::type c_type; public: - typedef typename range_detail::range_size_type_::BOOST_NESTED_TEMPLATE pts::type type; + typedef typename range_detail::range_size_type_::BOOST_NESTED_TEMPLATE pts::type type; }; } diff --git a/include/boost/range/size.hpp b/include/boost/range/size.hpp index 4b4eebe..6ae74d1 100644 --- a/include/boost/range/size.hpp +++ b/include/boost/range/size.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include namespace boost @@ -26,7 +26,7 @@ namespace boost namespace range_detail { template - inline BOOST_DEDUCED_TYPENAME range_difference::type + inline BOOST_DEDUCED_TYPENAME range_size::type range_calculate_size(const SinglePassRange& rng) { BOOST_ASSERT( (boost::end(rng) - boost::begin(rng)) >= 0 && @@ -36,7 +36,7 @@ namespace boost } template - inline BOOST_DEDUCED_TYPENAME range_difference::type + inline BOOST_DEDUCED_TYPENAME range_size::type size(const SinglePassRange& rng) { #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \ diff --git a/include/boost/range/size_type.hpp b/include/boost/range/size_type.hpp index 8c184f8..8223b75 100644 --- a/include/boost/range/size_type.hpp +++ b/include/boost/range/size_type.hpp @@ -16,11 +16,13 @@ #endif #include - +#include #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #include #else +#include +#include #include #include #include @@ -33,36 +35,44 @@ namespace boost ////////////////////////////////////////////////////////////////////////// // default ////////////////////////////////////////////////////////////////////////// - - template< typename C > + + template + class has_size_type + { + typedef char no_type; + struct yes_type { char dummy[2]; }; + + template + static yes_type test(BOOST_DEDUCED_TYPENAME C::size_type x); + + template + static no_type test(Arg x); + + public: + static const bool value = sizeof(test(0)) == sizeof(yes_type); + }; + + template struct range_size + { + typedef BOOST_DEDUCED_TYPENAME make_unsigned< + BOOST_DEDUCED_TYPENAME range_difference::type + >::type type; + }; + + template + struct range_size< + C, + BOOST_DEDUCED_TYPENAME enable_if, void>::type + > { typedef BOOST_DEDUCED_TYPENAME C::size_type type; }; - - ////////////////////////////////////////////////////////////////////////// - // pair - ////////////////////////////////////////////////////////////////////////// - - template< typename Iterator > - struct range_size< std::pair > - { - typedef std::size_t type; - }; - - ////////////////////////////////////////////////////////////////////////// - // array - ////////////////////////////////////////////////////////////////////////// - - template< typename T, std::size_t sz > - struct range_size< T[sz] > - { - typedef std::size_t type; - }; + } template< class T > - struct range_size : + struct range_size : detail::range_size { }; @@ -70,7 +80,7 @@ namespace boost struct range_size : detail::range_size { }; - + } // namespace boost #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION diff --git a/test/algorithm_test/for_each.cpp b/test/algorithm_test/for_each.cpp index 2ef51bf..701d676 100644 --- a/test/algorithm_test/for_each.cpp +++ b/test/algorithm_test/for_each.cpp @@ -44,7 +44,7 @@ namespace boost BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() ); fn_t result_fn2 = boost::for_each(boost::make_iterator_range(rng), fn_t(rng)); - BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn.invocation_count() ); + BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn2.invocation_count() ); // Test the constant version const SinglePassRange& cref_rng = rng; diff --git a/test/extension_size.cpp b/test/extension_size.cpp index 856f87d..b6f15cd 100644 --- a/test/extension_size.cpp +++ b/test/extension_size.cpp @@ -40,7 +40,7 @@ namespace boost_range_extension_size_test impl_t m_impl; }; - inline boost::range_difference >::type + inline boost::range_size >::type range_calculate_size(const FooWithoutSize& rng) { return 2u; From e6279d44364b81e3e0fa062eb091392d19393144 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 15 Apr 2012 12:18:02 +0000 Subject: [PATCH 13/41] [boost][range] - Ticket 6149 - as_literal causing unnecessary copy (on very silly compilers) [SVN r77992] --- include/boost/range/as_literal.hpp | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp index 2f04ca8..9ea144d 100644 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -25,7 +25,7 @@ #include #include -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR #include #endif @@ -38,72 +38,72 @@ namespace boost return strlen( s ); } -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR inline std::size_t length( const wchar_t* s ) { return wcslen( s ); } -#endif +#endif // // Remark: the compiler cannot choose between T* and T[sz] // overloads, so we must put the T* internal to the // unconstrained version. - // + // inline bool is_char_ptr( char* ) { return true; } - + inline bool is_char_ptr( const char* ) { return true; } -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR inline bool is_char_ptr( wchar_t* ) { return true; } - + inline bool is_char_ptr( const wchar_t* ) { return true; } #endif - + template< class T > - inline long is_char_ptr( T /* r */ ) + inline long is_char_ptr( const T& /* r */ ) { return 0L; } template< class T > - inline iterator_range + inline iterator_range make_range( T* const r, bool ) { return iterator_range( r, r + length(r) ); } template< class T > - inline iterator_range::type> + inline iterator_range::type> make_range( T& r, long ) { return boost::make_iterator_range( r ); } } - + template< class Range > - inline iterator_range::type> + inline iterator_range::type> as_literal( Range& r ) { return range_detail::make_range( r, range_detail::is_char_ptr(r) ); } template< class Range > - inline iterator_range::type> + inline iterator_range::type> as_literal( const Range& r ) { return range_detail::make_range( r, range_detail::is_char_ptr(r) ); @@ -112,9 +112,9 @@ namespace boost template< class Char, std::size_t sz > inline iterator_range as_literal( Char (&arr)[sz] ) { - return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); + return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); } - + template< class Char, std::size_t sz > inline iterator_range as_literal( const Char (&arr)[sz] ) { From 5a04c9e05bb62ccf2be15448e695fe913260ca86 Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Sun, 15 Apr 2012 12:24:53 +0000 Subject: [PATCH 14/41] [boost][range] - Ticket 5993 - Accumulate Concept Check constness. [SVN r77993] --- include/boost/range/numeric.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 include/boost/range/numeric.hpp diff --git a/include/boost/range/numeric.hpp b/include/boost/range/numeric.hpp old mode 100755 new mode 100644 index b01b73a..bfd1049 --- a/include/boost/range/numeric.hpp +++ b/include/boost/range/numeric.hpp @@ -40,7 +40,7 @@ namespace boost template< class SinglePassRange, class Value > inline Value accumulate( const SinglePassRange& rng, Value init ) { - BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); return std::accumulate( boost::begin(rng), boost::end(rng), init ); } From a72eae60992ef6737eefccb258017d3318fa0252 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 18 May 2012 04:44:04 +0000 Subject: [PATCH 15/41] Replace all uses of boost/utility.hpp with more-granular includes. Solves modularization dependency nightmare. [SVN r78502] --- include/boost/range/algorithm/for_each.hpp | 1 - include/boost/range/counting_range.hpp | 1 - include/boost/range/detail/any_iterator.hpp | 1 - include/boost/range/detail/any_iterator_buffer.hpp | 2 +- include/boost/range/detail/join_iterator.hpp | 2 +- include/boost/range/has_range_iterator.hpp | 2 +- include/boost/range/size_type.hpp | 2 +- 7 files changed, 4 insertions(+), 7 deletions(-) mode change 100755 => 100644 include/boost/range/algorithm/for_each.hpp mode change 100755 => 100644 include/boost/range/counting_range.hpp diff --git a/include/boost/range/algorithm/for_each.hpp b/include/boost/range/algorithm/for_each.hpp old mode 100755 new mode 100644 index 12c9d4d..4f5108d --- a/include/boost/range/algorithm/for_each.hpp +++ b/include/boost/range/algorithm/for_each.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #if BOOST_WORKAROUND(BOOST_MSVC, == 1600) diff --git a/include/boost/range/counting_range.hpp b/include/boost/range/counting_range.hpp old mode 100755 new mode 100644 index 72733a2..b8e4e3a --- a/include/boost/range/counting_range.hpp +++ b/include/boost/range/counting_range.hpp @@ -18,7 +18,6 @@ #include #include #include -#include namespace boost { diff --git a/include/boost/range/detail/any_iterator.hpp b/include/boost/range/detail/any_iterator.hpp index 107dfd6..5705ff0 100644 --- a/include/boost/range/detail/any_iterator.hpp +++ b/include/boost/range/detail/any_iterator.hpp @@ -11,7 +11,6 @@ #define BOOST_RANGE_DETAIL_ANY_ITERATOR_HPP_INCLUDED #include -#include #include #include #include diff --git a/include/boost/range/detail/any_iterator_buffer.hpp b/include/boost/range/detail/any_iterator_buffer.hpp index 26c1420..2bb5d53 100644 --- a/include/boost/range/detail/any_iterator_buffer.hpp +++ b/include/boost/range/detail/any_iterator_buffer.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace boost { diff --git a/include/boost/range/detail/join_iterator.hpp b/include/boost/range/detail/join_iterator.hpp index ce86467..bbdeec7 100644 --- a/include/boost/range/detail/join_iterator.hpp +++ b/include/boost/range/detail/join_iterator.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace boost { diff --git a/include/boost/range/has_range_iterator.hpp b/include/boost/range/has_range_iterator.hpp index 432efad..8046eb4 100644 --- a/include/boost/range/has_range_iterator.hpp +++ b/include/boost/range/has_range_iterator.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace boost { diff --git a/include/boost/range/size_type.hpp b/include/boost/range/size_type.hpp index 8223b75..c6fb54b 100644 --- a/include/boost/range/size_type.hpp +++ b/include/boost/range/size_type.hpp @@ -21,7 +21,7 @@ #include #else -#include +#include #include #include #include From dceccc9de9801e36ff682a6f3261513889f44fff Mon Sep 17 00:00:00 2001 From: Neil Groves Date: Fri, 29 Jun 2012 21:49:37 +0000 Subject: [PATCH 16/41] [boost][range] - Added the missing include of boost/utility/enable_if.hpp to boost/range/algorithm/for_each.hpp [SVN r79180] --- include/boost/range/algorithm/for_each.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/range/algorithm/for_each.hpp b/include/boost/range/algorithm/for_each.hpp index 4f5108d..fe8ab80 100644 --- a/include/boost/range/algorithm/for_each.hpp +++ b/include/boost/range/algorithm/for_each.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include From 665c4a3234b470040105abf6a1e91e57e6b3d9de Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Thu, 13 Dec 2012 07:01:39 +0000 Subject: [PATCH 17/41] [range] fixed a typo in the docs, introduced in r77990, that messed up the sections [SVN r81888] --- doc/html/index.html | 9 +- doc/html/quickbook_HTML.manifest | 1 + doc/html/range/concepts.html | 5 +- .../range/concepts/bidirectional_range.html | 55 +++--- doc/html/range/concepts/concept_checking.html | 14 +- doc/html/range/concepts/forward_range.html | 37 ++-- doc/html/range/concepts/overview.html | 5 +- .../range/concepts/random_access_range.html | 42 ++--- .../range/concepts/single_pass_range.html | 54 +++--- doc/html/range/examples.html | 5 +- doc/html/range/faq.html | 5 +- doc/html/range/headers.html | 5 +- doc/html/range/headers/adaptors.html | 5 +- doc/html/range/headers/algorithm.html | 5 +- doc/html/range/headers/algorithm_ext.html | 5 +- doc/html/range/headers/general.html | 5 +- doc/html/range/history_ack.html | 19 ++- doc/html/range/introduction.html | 30 ++-- doc/html/range/mfc_atl.html | 18 +- doc/html/range/mfc_atl/atl_ranges.html | 5 +- doc/html/range/mfc_atl/const_ranges.html | 6 +- doc/html/range/mfc_atl/mfc_ranges.html | 5 +- doc/html/range/mfc_atl/references.html | 5 +- doc/html/range/mfc_atl/requirements.html | 5 +- doc/html/range/portability.html | 21 ++- doc/html/range/reference.html | 5 +- doc/html/range/reference/adaptors.html | 5 +- .../adaptors/general_requirements.html | 7 +- .../reference/adaptors/introduction.html | 38 ++--- .../range/reference/adaptors/reference.html | 5 +- .../adaptors/reference/adjacent_filtered.html | 10 +- .../reference/adaptors/reference/copied.html | 10 +- .../adaptors/reference/filtered.html | 10 +- .../reference/adaptors/reference/indexed.html | 10 +- .../adaptors/reference/indirected.html | 10 +- .../adaptors/reference/map_keys.html | 10 +- .../adaptors/reference/map_values.html | 10 +- .../adaptors/reference/replaced.html | 32 ++-- .../adaptors/reference/replaced_if.html | 30 ++-- .../adaptors/reference/reversed.html | 10 +- .../reference/adaptors/reference/sliced.html | 10 +- .../reference/adaptors/reference/strided.html | 10 +- .../adaptors/reference/tokenized.html | 45 +++-- .../adaptors/reference/transformed.html | 10 +- .../adaptors/reference/type_erased.html | 161 +++++++++--------- .../reference/adaptors/reference/uniqued.html | 10 +- doc/html/range/reference/algorithms.html | 5 +- doc/html/range/reference/algorithms/heap.html | 5 +- .../reference/algorithms/heap/make_heap.html | 36 ++-- .../reference/algorithms/heap/pop_heap.html | 42 ++--- .../reference/algorithms/heap/push_heap.html | 42 ++--- .../reference/algorithms/heap/sort_heap.html | 42 ++--- .../reference/algorithms/introduction.html | 23 ++- .../range/reference/algorithms/mutating.html | 5 +- .../reference/algorithms/mutating/copy.html | 42 ++--- .../algorithms/mutating/copy_backward.html | 42 ++--- .../reference/algorithms/mutating/fill.html | 36 ++-- .../reference/algorithms/mutating/fill_n.html | 36 ++-- .../algorithms/mutating/generate.html | 42 ++--- .../algorithms/mutating/inplace_merge.html | 54 +++--- .../reference/algorithms/mutating/merge.html | 54 +++--- .../algorithms/mutating/nth_element.html | 36 ++-- .../algorithms/mutating/partial_sort.html | 36 ++-- .../algorithms/mutating/partition.html | 36 ++-- .../algorithms/mutating/random_shuffle.html | 42 ++--- .../reference/algorithms/mutating/remove.html | 36 ++-- .../algorithms/mutating/remove_copy.html | 36 ++-- .../algorithms/mutating/remove_copy_if.html | 36 ++-- .../algorithms/mutating/remove_if.html | 36 ++-- .../algorithms/mutating/replace.html | 36 ++-- .../algorithms/mutating/replace_copy.html | 36 ++-- .../algorithms/mutating/replace_copy_if.html | 36 ++-- .../algorithms/mutating/replace_if.html | 36 ++-- .../algorithms/mutating/reverse.html | 36 ++-- .../algorithms/mutating/reverse_copy.html | 36 ++-- .../reference/algorithms/mutating/rotate.html | 42 ++--- .../algorithms/mutating/rotate_copy.html | 42 ++--- .../reference/algorithms/mutating/sort.html | 36 ++-- .../algorithms/mutating/stable_partition.html | 36 ++-- .../algorithms/mutating/stable_sort.html | 36 ++-- .../algorithms/mutating/swap_ranges.html | 36 ++-- .../algorithms/mutating/transform.html | 42 ++--- .../reference/algorithms/mutating/unique.html | 36 ++-- .../algorithms/mutating/unique_copy.html | 36 ++-- doc/html/range/reference/algorithms/new.html | 5 +- .../reference/algorithms/new/copy_n.html | 36 ++-- .../range/reference/algorithms/new/erase.html | 36 ++-- .../reference/algorithms/new/for_each.html | 36 ++-- .../reference/algorithms/new/insert.html | 36 ++-- .../range/reference/algorithms/new/iota.html | 36 ++-- .../reference/algorithms/new/is_sorted.html | 36 ++-- .../reference/algorithms/new/overwrite.html | 36 ++-- .../reference/algorithms/new/push_back.html | 36 ++-- .../reference/algorithms/new/push_front.html | 36 ++-- .../algorithms/new/remove_erase.html | 36 ++-- .../algorithms/new/remove_erase_if.html | 36 ++-- .../reference/algorithms/non_mutating.html | 5 +- .../non_mutating/adjacent_find.html | 36 ++-- .../non_mutating/binary_search.html | 42 ++--- .../algorithms/non_mutating/count.html | 36 ++-- .../algorithms/non_mutating/count_if.html | 36 ++-- .../algorithms/non_mutating/equal.html | 36 ++-- .../algorithms/non_mutating/equal_range.html | 46 ++--- .../algorithms/non_mutating/find.html | 36 ++-- .../algorithms/non_mutating/find_end.html | 36 ++-- .../non_mutating/find_first_of.html | 36 ++-- .../algorithms/non_mutating/find_if.html | 42 ++--- .../algorithms/non_mutating/for_each.html | 38 ++--- .../non_mutating/lexicographical_compare.html | 38 ++--- .../algorithms/non_mutating/lower_bound.html | 42 ++--- .../algorithms/non_mutating/max_element.html | 36 ++-- .../algorithms/non_mutating/min_element.html | 36 ++-- .../algorithms/non_mutating/mismatch.html | 42 ++--- .../algorithms/non_mutating/search.html | 36 ++-- .../algorithms/non_mutating/search_n.html | 36 ++-- .../algorithms/non_mutating/upper_bound.html | 42 ++--- .../range/reference/algorithms/numeric.html | 5 +- .../algorithms/numeric/accumulate.html | 48 +++--- .../numeric/adjacent_difference.html | 54 +++--- .../algorithms/numeric/inner_product.html | 54 +++--- .../algorithms/numeric/partial_sum.html | 54 +++--- .../reference/algorithms/permutation.html | 5 +- .../permutation/next_permutation.html | 36 ++-- .../permutation/prev_permutation.html | 36 ++-- doc/html/range/reference/algorithms/set.html | 5 +- .../reference/algorithms/set/includes.html | 44 ++--- .../algorithms/set/set_difference.html | 42 ++--- .../algorithms/set/set_intersection.html | 44 ++--- .../set/set_symmetric_difference.html | 44 ++--- .../reference/algorithms/set/set_union.html | 46 ++--- .../reference/concept_implementation.html | 5 +- .../concept_implementation/semantics.html | 11 +- .../semantics/functions.html | 7 +- .../semantics/metafunctions.html | 7 +- .../concept_implementation/synopsis.html | 104 +++++------ doc/html/range/reference/extending.html | 5 +- .../range/reference/extending/method_1.html | 5 +- .../range/reference/extending/method_2.html | 76 ++++----- .../range/reference/extending/method_3.html | 5 +- .../extending/method_3/method_3_1.html | 10 +- .../extending/method_3/method_3_2.html | 10 +- doc/html/range/reference/overview.html | 5 +- doc/html/range/reference/ranges.html | 5 +- .../range/reference/ranges/any_range.html | 24 +-- .../reference/ranges/counting_range.html | 30 ++-- doc/html/range/reference/ranges/irange.html | 36 ++-- .../range/reference/ranges/istream_range.html | 24 +-- doc/html/range/reference/utilities.html | 5 +- .../reference/utilities/iterator_range.html | 110 ++++++------ doc/html/range/reference/utilities/join.html | 18 +- .../range/reference/utilities/sub_range.html | 57 +++---- doc/html/range/style_guide.html | 53 +++--- doc/html/range/upgrade.html | 13 +- doc/html/range/upgrade/upgrade_from_1_34.html | 5 +- doc/html/range/upgrade/upgrade_from_1_42.html | 5 +- doc/html/range/upgrade/upgrade_from_1_45.html | 11 +- doc/html/range/upgrade/upgrade_from_1_49.html | 50 ++++++ doc/upgrade.qbk | 2 + 158 files changed, 2299 insertions(+), 2227 deletions(-) create mode 100644 doc/html/range/upgrade/upgrade_from_1_49.html diff --git a/doc/html/index.html b/doc/html/index.html index 1be23d5..01dcdb6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -28,9 +28,10 @@

Neil Groves

-
+
-

+

Distributed under 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)

@@ -122,6 +123,8 @@
Upgrade version of Boost.Range
+
Upgrade from version + 1.49
Upgrade from version 1.45
Upgrade from version @@ -144,7 +147,7 @@

- +

Last revised: January 01, 2011 at 16:31:27 GMT

Last revised: December 13, 2012 at 06:35:02 GMT


diff --git a/doc/html/quickbook_HTML.manifest b/doc/html/quickbook_HTML.manifest index 1b32f72..27afd8c 100644 --- a/doc/html/quickbook_HTML.manifest +++ b/doc/html/quickbook_HTML.manifest @@ -147,6 +147,7 @@ range/mfc_atl/atl_ranges.html range/mfc_atl/const_ranges.html range/mfc_atl/references.html range/upgrade.html +range/upgrade/upgrade_from_1_49.html range/upgrade/upgrade_from_1_45.html range/upgrade/upgrade_from_1_42.html range/upgrade/upgrade_from_1_34.html diff --git a/doc/html/range/concepts.html b/doc/html/range/concepts.html index c3c92a8..f78f33b 100644 --- a/doc/html/range/concepts.html +++ b/doc/html/range/concepts.html @@ -22,7 +22,7 @@
-
+
@@ -37,7 +37,8 @@
-