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 e0087fb..afab584 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -31,6 +31,22 @@ 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 ] [ range-test adaptor_test/filtered ] @@ -155,5 +171,9 @@ 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_5547 ] + [ range-test ticket_5556_is_sorted_namespace ] ; diff --git a/test/adaptor_test/strided.cpp b/test/adaptor_test/strided.cpp index 91beb81..1198a10 100644 --- a/test/adaptor_test/strided.cpp +++ b/test/adaptor_test/strided.cpp @@ -250,6 +250,38 @@ namespace boost BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), output.begin(), output.end() ); } + + template + 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 ); + } + + void strided_test_ticket_5236() + { + 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) ); + } + } } @@ -262,6 +294,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; } 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 index 00987e4..5249c58 100644 --- 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/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/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 ) ); diff --git a/test/irange.cpp b/test/irange.cpp index d71f184..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() ); } @@ -81,7 +91,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 +123,27 @@ namespace boost test_irange(10, 0, -1); 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); + + 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); + + 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/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 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; +} 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; +} 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; +} 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; +}