mirror of
https://github.com/boostorg/range.git
synced 2026-01-25 00:12:22 +01:00
[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:
@@ -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 ]
|
||||
;
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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<char>();
|
||||
test_istream_range_impl<wchar_t>();
|
||||
}
|
||||
|
||||
} // namespace anonymous namespace
|
||||
|
||||
|
||||
@@ -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
24
test/test_utils.hpp
Normal 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
46
test/ticket_6944.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user