diff --git a/include/boost/range/adaptor/indexed.hpp b/include/boost/range/adaptor/indexed.hpp old mode 100755 new mode 100644 index 5a523ce..cb2c127 --- a/include/boost/range/adaptor/indexed.hpp +++ b/include/boost/range/adaptor/indexed.hpp @@ -55,6 +55,9 @@ namespace boost index_type m_index; public: + indexed_iterator() + : m_index(index_type()) {} + explicit indexed_iterator( Iter i, index_type index ) : base(i), m_index(index) { diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index 5965293..5a02a21 100644 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -330,8 +330,8 @@ namespace boost { struct BidirectionalRangeConcept : ForwardRangeConcept { #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT - BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept)); - BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept)); #endif }; @@ -348,8 +348,8 @@ namespace boost { struct RandomAccessRangeConcept : BidirectionalRangeConcept { #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT - BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept)); - BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept)); #endif }; diff --git a/include/boost/range/detail/extract_optional_type.hpp b/include/boost/range/detail/extract_optional_type.hpp old mode 100755 new mode 100644 index 8292e34..4a7f71a --- a/include/boost/range/detail/extract_optional_type.hpp +++ b/include/boost/range/detail/extract_optional_type.hpp @@ -16,7 +16,7 @@ #include -#ifdef BOOST_NO_PARTIAL_TEMPLATE_SPECIALIZATION +#ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS #define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ template< typename C > \ diff --git a/include/boost/range/irange.hpp b/include/boost/range/irange.hpp index 248124f..f35df47 100644 --- a/include/boost/range/irange.hpp +++ b/include/boost/range/irange.hpp @@ -217,7 +217,7 @@ namespace boost 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; + const std::ptrdiff_t num_steps = (l - f) / sz + ((l - f) % sz ? 1 : 0); BOOST_ASSERT(num_steps >= 0); return strided_integer_range( diff --git a/include/boost/range/istream_range.hpp b/include/boost/range/istream_range.hpp old mode 100755 new mode 100644 index c3f2248..a486317 --- a/include/boost/range/istream_range.hpp +++ b/include/boost/range/istream_range.hpp @@ -14,7 +14,7 @@ */ #include -#include +#include #include #include @@ -27,8 +27,8 @@ namespace boost istream_range(std::basic_istream& in) { return iterator_range >( - std::istream_iterator(in), - std::istream_iterator()); + std::istream_iterator(in), + std::istream_iterator()); } } // namespace range using range::istream_range; diff --git a/include/boost/range/iterator_range_core.hpp b/include/boost/range/iterator_range_core.hpp index 60c7670..6e68992 100644 --- a/include/boost/range/iterator_range_core.hpp +++ b/include/boost/range/iterator_range_core.hpp @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -167,7 +169,8 @@ namespace boost private: // for return value of operator()() typedef BOOST_DEDUCED_TYPENAME - boost::mpl::if_< boost::is_abstract, + boost::mpl::if_< boost::mpl::or_< boost::is_abstract< value_type >, + boost::is_array< value_type > >, reference, value_type >::type abstract_value_type; public: diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d76c141..bcaa772 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -161,5 +161,6 @@ test-suite range : [ range-test ticket_5544_terminate_irange ] [ range-test ticket_5547 ] [ range-test ticket_5556_is_sorted_namespace ] + [ range-test ticket_6944 ] ; diff --git a/test/adaptor_test/indexed.cpp b/test/adaptor_test/indexed.cpp index 2a9c45d..a5bef4d 100644 --- a/test/adaptor_test/indexed.cpp +++ b/test/adaptor_test/indexed.cpp @@ -15,11 +15,14 @@ #include #include +#include #include #include #include +#include "../test_utils.hpp" + namespace boost { namespace @@ -83,6 +86,9 @@ namespace boost { indexed_test_impl< std::vector< int > >(); indexed_test_impl< std::list< int > >(); + + check_random_access_range_concept(std::vector() | boost::adaptors::indexed(0)); + check_bidirectional_range_concept(std::list() | boost::adaptors::indexed(0)); } } } diff --git a/test/irange.cpp b/test/irange.cpp index 358a2b1..659401b 100644 --- a/test/irange.cpp +++ b/test/irange.cpp @@ -35,15 +35,6 @@ namespace boost 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(IntegerInput first, IntegerInput last, int step) @@ -58,9 +49,12 @@ namespace boost std::vector reference; - 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) + const std::ptrdiff_t first_p = static_cast(first); + const std::ptrdiff_t last_p = static_cast(last); + const std::ptrdiff_t step_p = static_cast(step); + for (std::ptrdiff_t current_value = first_p; + step_p >= 0 ? current_value < last_p : current_value > last_p; + current_value += step_p) reference.push_back(current_value); std::vector test; diff --git a/test/istream_range.cpp b/test/istream_range.cpp index b3e16db..7d10313 100644 --- a/test/istream_range.cpp +++ b/test/istream_range.cpp @@ -19,15 +19,15 @@ namespace { - // Test an integer range with a step size of 1. - void test_istream_range() + template + void test_istream_range_impl() { - std::stringstream s; + std::basic_stringstream s; std::vector reference; for (int i = 0; i < 10; ++i) { reference.push_back(i); - s << i << " "; + s << i << CharT(' '); } std::vector target; @@ -36,6 +36,13 @@ namespace BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), target.begin(), target.end() ); } + + // Test an istream range. + void test_istream_range() + { + test_istream_range_impl(); + test_istream_range_impl(); + } } // namespace anonymous namespace diff --git a/test/iterator_range.cpp b/test/iterator_range.cpp index a53ef16..c914f43 100644 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -101,6 +101,11 @@ void check_iterator_range() BOOST_CHECK( rrr == str ); check_reference_type(); + + // Check that an iterator range can be instantiated with + // a pointer to an array as an iterator. + int arr[2][2]; + boost::make_iterator_range(arr, arr + 2); } namespace iterator_range_test_detail diff --git a/test/test_utils.hpp b/test/test_utils.hpp new file mode 100644 index 0000000..7af920a --- /dev/null +++ b/test/test_utils.hpp @@ -0,0 +1,24 @@ +// Boost.Range library +// +// Copyright Akira Takahashi 2013. Use, modification and +// distribution is subject to the Boost Software License, Version +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// +// For more information, see http://www.boost.org/libs/range/ +// + +#include + +template +void check_random_access_range_concept(const RandomAccessRng& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept )); +} + +template +void check_bidirectional_range_concept(const BidirectionalRng& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( boost::BidirectionalRangeConcept )); +} diff --git a/test/ticket_6944.cpp b/test/ticket_6944.cpp new file mode 100644 index 0000000..43796a8 --- /dev/null +++ b/test/ticket_6944.cpp @@ -0,0 +1,46 @@ +// 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 + +#include + +namespace boost +{ + typedef std::vector::iterator iter_base; + struct iter : boost::iterator_adaptor {}; // will be deduced as random-access traversal but input category + typedef boost::iterator_range iter_range; + + namespace + { + // Ticket 6944 - Some Range concepts use the incorrect Iterator concept + void test_ticket_6944() + { + BOOST_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept )); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.ticket_6944" ); + + test->add( BOOST_TEST_CASE( &boost::test_ticket_6944 ) ); + + return test; +}