[range] Merge Boost.Range bug fixes to release branch (fixes #6944; fixes #7407; fixes #7408; fixes #7731; fixes #7827; fixes #8338; fixes #8453).

[SVN r84823]
This commit is contained in:
Nathan Ridge
2013-06-18 02:22:07 +00:00
parent 58d57f9b7b
commit 43d2ca8549
13 changed files with 115 additions and 26 deletions

3
include/boost/range/adaptor/indexed.hpp Executable file → Normal file
View File

@ -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)
{

View File

@ -330,8 +330,8 @@ namespace boost {
struct BidirectionalRangeConcept : ForwardRangeConcept<T>
{
#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::iterator>));
BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::const_iterator>));
BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::iterator>));
BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::const_iterator>));
#endif
};
@ -348,8 +348,8 @@ namespace boost {
struct RandomAccessRangeConcept : BidirectionalRangeConcept<T>
{
#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::iterator>));
BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::const_iterator>));
BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::iterator>));
BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::const_iterator>));
#endif
};

2
include/boost/range/detail/extract_optional_type.hpp Executable file → Normal file
View File

@ -16,7 +16,7 @@
#include <boost/config.hpp>
#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 > \

View File

@ -217,7 +217,7 @@ namespace boost
const std::ptrdiff_t sz = static_cast<std::ptrdiff_t>(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<Integer>(

6
include/boost/range/istream_range.hpp Executable file → Normal file
View File

@ -14,7 +14,7 @@
*/
#include <iterator>
#include <istream>
#include <iosfwd>
#include <boost/config.hpp>
#include <boost/range/iterator_range.hpp>
@ -27,8 +27,8 @@ namespace boost
istream_range(std::basic_istream<Elem, Traits>& in)
{
return iterator_range<std::istream_iterator<Type, Elem, Traits> >(
std::istream_iterator<Type>(in),
std::istream_iterator<Type>());
std::istream_iterator<Type, Elem, Traits>(in),
std::istream_iterator<Type, Elem, Traits>());
}
} // namespace range
using range::istream_range;

View File

@ -21,7 +21,9 @@
#include <boost/assert.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_abstract.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/range/functions.hpp>
#include <boost/range/iterator.hpp>
@ -167,7 +169,8 @@ namespace boost
private: // for return value of operator()()
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::if_< boost::is_abstract<value_type>,
boost::mpl::if_< boost::mpl::or_< boost::is_abstract< value_type >,
boost::is_array< value_type > >,
reference, value_type >::type abstract_value_type;
public:

View File

@ -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 ]
;

View File

@ -15,11 +15,14 @@
#include <boost/assign.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
#include <list>
#include <vector>
#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<int>() | boost::adaptors::indexed(0));
check_bidirectional_range_concept(std::list<int>() | boost::adaptors::indexed(0));
}
}
}

View File

@ -35,15 +35,6 @@ namespace boost
reference.begin(), reference.end() );
}
template<typename Integer>
std::ptrdiff_t test_irange_calculate_num_steps(Integer first, Integer last, int step)
{
const std::ptrdiff_t sz = static_cast<std::ptrdiff_t>(step >= 0 ? step : -step);
const std::ptrdiff_t l = static_cast<std::ptrdiff_t>(step >= 0 ? last : first);
const std::ptrdiff_t f = static_cast<std::ptrdiff_t>(step >= 0 ? first : last);
return (l + ((l-f) % sz) - f) / sz;
}
// Test an integer range with a runtime specified step size.
template<typename Integer, typename IntegerInput>
void test_irange_impl(IntegerInput first, IntegerInput last, int step)
@ -58,9 +49,12 @@ namespace boost
std::vector<Integer> 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<std::ptrdiff_t>(first);
const std::ptrdiff_t last_p = static_cast<std::ptrdiff_t>(last);
const std::ptrdiff_t step_p = static_cast<std::ptrdiff_t>(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<Integer> test;

View File

@ -19,15 +19,15 @@
namespace
{
// Test an integer range with a step size of 1.
void test_istream_range()
template <typename CharT>
void test_istream_range_impl()
{
std::stringstream s;
std::basic_stringstream<CharT> s;
std::vector<int> reference;
for (int i = 0; i < 10; ++i)
{
reference.push_back(i);
s << i << " ";
s << i << CharT(' ');
}
std::vector<int> target;
@ -37,6 +37,13 @@ namespace
target.begin(), target.end() );
}
// Test an istream range.
void test_istream_range()
{
test_istream_range_impl<char>();
test_istream_range_impl<wchar_t>();
}
} // namespace anonymous namespace
boost::unit_test::test_suite*

View File

@ -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

24
test/test_utils.hpp Normal file
View File

@ -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 <boost/range/concepts.hpp>
template <class RandomAccessRng>
void check_random_access_range_concept(const RandomAccessRng& rng)
{
BOOST_RANGE_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<RandomAccessRng> ));
}
template <class BidirectionalRng>
void check_bidirectional_range_concept(const BidirectionalRng& rng)
{
BOOST_RANGE_CONCEPT_ASSERT(( boost::BidirectionalRangeConcept<BidirectionalRng> ));
}

46
test/ticket_6944.cpp Normal file
View File

@ -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 <boost/concept_check.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/range/concepts.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
namespace boost
{
typedef std::vector<int>::iterator iter_base;
struct iter : boost::iterator_adaptor<iter, iter_base, int, boost::use_default, int> {}; // will be deduced as random-access traversal but input category
typedef boost::iterator_range<iter> iter_range;
namespace
{
// Ticket 6944 - Some Range concepts use the incorrect Iterator concept
void test_ticket_6944()
{
BOOST_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<iter_range> ));
}
}
}
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;
}