forked from boostorg/range
Compare commits
1 Commits
boost-1.69
...
revert-43-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51fbb45ab5 |
151
.travis.yml
151
.travis.yml
@@ -1,151 +0,0 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.4
|
||||
env: TOOLSET=gcc-4.4 CXXSTD=98,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.4
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.6
|
||||
env: TOOLSET=gcc-4.6 CXXSTD=03,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc-5 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc-5 CXXSTD=14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc-6 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc-6 CXXSTD=14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc-7 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc-7 CXXSTD=14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=03,11
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=03,11
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang CXXSTD=14,1z
|
||||
|
||||
install:
|
||||
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
||||
- cd ..
|
||||
- git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/range
|
||||
- python tools/boostdep/depinst/depinst.py range
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- ./b2 -j 3 libs/range/test toolset=$TOOLSET cxxstd=$CXXSTD
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
||||
@@ -10,11 +10,7 @@
|
||||
``
|
||||
template<class Integer>
|
||||
iterator_range< range_detail::integer_iterator<Integer> >
|
||||
irange(Integer last);
|
||||
|
||||
template<class Integer>
|
||||
iterator_range< range_detail::integer_iterator<Integer> >
|
||||
irange(Integer first, Integer last);
|
||||
irange(Integer first, Integer last);
|
||||
|
||||
template<class Integer, class StepSize>
|
||||
iterator_range< range_detail::integer_iterator_with_step<Integer, StepSize> >
|
||||
@@ -41,3 +37,4 @@ Defined in the header file `boost/range/irange.hpp`
|
||||
Constant. Since this function generates a new range the most significant performance cost is incurred through the iteration of the generated range.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/range/reference.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/type_traits/declval.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE)
|
||||
@@ -32,7 +32,7 @@ namespace boost
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
range_reference<SinglePassRange>::type argument_type;
|
||||
|
||||
typedef decltype( boost::declval<argument_type>().get() ) result_type;
|
||||
using result_type = decltype(std::declval<argument_type>().get() );
|
||||
|
||||
result_type operator()( argument_type &&r ) const
|
||||
{
|
||||
@@ -46,11 +46,11 @@ namespace boost
|
||||
: public transformed_range<unwrap_ref<SinglePassRange>,
|
||||
SinglePassRange>
|
||||
{
|
||||
typedef transformed_range<unwrap_ref<SinglePassRange>,
|
||||
SinglePassRange> base;
|
||||
using base = transformed_range<unwrap_ref<SinglePassRange>,
|
||||
SinglePassRange>;
|
||||
public:
|
||||
typedef unwrap_ref<SinglePassRange> transform_fn_type;
|
||||
typedef SinglePassRange source_range_type;
|
||||
using transform_fn_type = unwrap_ref<SinglePassRange>;
|
||||
using source_range_type = SinglePassRange;
|
||||
|
||||
unwrap_ref_range(transform_fn_type fn, source_range_type &rng)
|
||||
: base(fn, rng)
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <boost/range/size_type.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -32,12 +32,12 @@ struct wrap_rand
|
||||
{
|
||||
typedef unsigned int result_type;
|
||||
|
||||
static BOOST_CONSTEXPR result_type (min)()
|
||||
static result_type (min)()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOST_CONSTEXPR result_type (max)()
|
||||
static result_type (max)()
|
||||
{
|
||||
return RAND_MAX;
|
||||
}
|
||||
@@ -64,12 +64,12 @@ struct wrap_generator
|
||||
|
||||
wrap_generator(Generator& gen) : g(gen) {}
|
||||
|
||||
static BOOST_CONSTEXPR result_type (min)()
|
||||
static result_type (min)()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOST_CONSTEXPR result_type (max)()
|
||||
static result_type (max)()
|
||||
{
|
||||
return max_arg - 1;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,37 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
namespace range_detail
|
||||
{
|
||||
|
||||
template < class Container, class Range >
|
||||
inline Container& push_back_impl( Container& on, Range&& from, std::false_type)
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Range> ));
|
||||
BOOST_ASSERT_MSG(!range_detail::is_same_object(on, from),
|
||||
"cannot move from a container to itself");
|
||||
on.insert( on.end(),
|
||||
std::make_move_iterator(boost::begin(from)),
|
||||
std::make_move_iterator(boost::end(from)));
|
||||
return on;
|
||||
}
|
||||
|
||||
template < class Container, class Range >
|
||||
inline Container& push_back_impl( Container& on, const Range& from, std::true_type)
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const Range> ));
|
||||
BOOST_ASSERT_MSG(!range_detail::is_same_object(on, from),
|
||||
"cannot copy from a container to itself");
|
||||
on.insert( on.end(), boost::begin(from), boost::end(from));
|
||||
return on;
|
||||
}
|
||||
|
||||
} //namespace range_detail
|
||||
#endif
|
||||
|
||||
namespace range {
|
||||
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
template< class Container, class Range >
|
||||
inline Container& push_back( Container& on, const Range& from )
|
||||
{
|
||||
@@ -34,6 +62,19 @@ inline Container& push_back( Container& on, const Range& from )
|
||||
return on;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template< class Container, class Range >
|
||||
inline Container& push_back( Container& on, Range&& from )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Container> ));
|
||||
range_detail::push_back_impl(on,
|
||||
std::forward<Range>(from),
|
||||
std::is_lvalue_reference<Range>() );
|
||||
return on;
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace range
|
||||
using range::push_back;
|
||||
} // namespace boost
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#else
|
||||
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -96,10 +94,7 @@ namespace range_adl_barrier
|
||||
{
|
||||
|
||||
template< class T >
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
|
||||
BOOST_CONSTEXPR inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
using namespace range_detail;
|
||||
@@ -108,10 +103,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
|
||||
}
|
||||
|
||||
template< class T >
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
|
||||
BOOST_CONSTEXPR inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
using namespace range_detail;
|
||||
|
||||
@@ -252,7 +252,7 @@ namespace boost {
|
||||
n = i - j;
|
||||
}
|
||||
private:
|
||||
BOOST_DEDUCED_TYPENAME BidirectionalIteratorConcept<Iterator>::difference_type n;
|
||||
BOOST_DEDUCED_TYPENAME RandomAccessIteratorConcept::difference_type n;
|
||||
Iterator i;
|
||||
Iterator j;
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/utility/addressof.hpp>
|
||||
#include <boost/utility/enable_if.hpp> // disable_if
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
#if !defined(BOOST_RANGE_DETAIL_MICROSOFT_RANGE_VERSION_1)
|
||||
#include <boost/range/mutable_iterator.hpp>
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -23,18 +23,13 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace range_distance_adl_barrier
|
||||
template< class T >
|
||||
inline BOOST_CXX14_CONSTEXPR BOOST_DEDUCED_TYPENAME range_difference<T>::type
|
||||
distance( const T& r )
|
||||
{
|
||||
template< class T >
|
||||
inline BOOST_CXX14_CONSTEXPR BOOST_DEDUCED_TYPENAME range_difference<T>::type
|
||||
distance( const T& r )
|
||||
{
|
||||
return boost::iterators::distance( boost::begin( r ), boost::end( r ) );
|
||||
}
|
||||
return boost::distance( boost::begin( r ), boost::end( r ) );
|
||||
}
|
||||
|
||||
using namespace range_distance_adl_barrier;
|
||||
|
||||
} // namespace 'boost'
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include <boost/range/detail/implementation_help.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/const_iterator.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -90,10 +88,7 @@ namespace range_adl_barrier
|
||||
{
|
||||
|
||||
template< class T >
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type end( T& r )
|
||||
BOOST_CONSTEXPR inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type end( T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
using namespace range_detail;
|
||||
@@ -102,10 +97,7 @@ inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type end( T& r )
|
||||
}
|
||||
|
||||
template< class T >
|
||||
#if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
BOOST_CONSTEXPR
|
||||
#endif
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type end( const T& r )
|
||||
BOOST_CONSTEXPR inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type end( const T& r )
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
using namespace range_detail;
|
||||
|
||||
@@ -203,6 +203,22 @@ namespace boost
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Integer>
|
||||
integer_range<Integer>
|
||||
irange(int last)
|
||||
{
|
||||
BOOST_ASSERT( 0 <= last );
|
||||
return integer_range<Integer>(0, last);
|
||||
}
|
||||
|
||||
template<typename Integer>
|
||||
integer_range<Integer>
|
||||
irange(int first, int last)
|
||||
{
|
||||
BOOST_ASSERT( first <= last );
|
||||
return integer_range<Integer>(first, last);
|
||||
}
|
||||
|
||||
template<typename Integer>
|
||||
integer_range<Integer>
|
||||
irange(Integer first, Integer last)
|
||||
@@ -217,7 +233,7 @@ namespace boost
|
||||
{
|
||||
BOOST_ASSERT( step_size != 0 );
|
||||
BOOST_ASSERT( (step_size > 0) ? (last >= first) : (last <= first) );
|
||||
|
||||
|
||||
typedef typename range_detail::integer_iterator_with_step<Integer> iterator_t;
|
||||
|
||||
const std::ptrdiff_t sz = static_cast<std::ptrdiff_t>(step_size >= 0 ? step_size : -step_size);
|
||||
@@ -225,19 +241,12 @@ namespace boost
|
||||
const Integer f = step_size >= 0 ? first : last;
|
||||
const std::ptrdiff_t num_steps = (l - f) / sz + ((l - f) % sz ? 1 : 0);
|
||||
BOOST_ASSERT(num_steps >= 0);
|
||||
|
||||
|
||||
return strided_integer_range<Integer>(
|
||||
iterator_t(first, 0, step_size),
|
||||
iterator_t(first, num_steps, step_size));
|
||||
}
|
||||
|
||||
template<typename Integer>
|
||||
integer_range<Integer>
|
||||
irange(Integer last)
|
||||
{
|
||||
return integer_range<Integer>(static_cast<Integer>(0), last);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include <boost/range/algorithm/equal.hpp>
|
||||
#include <boost/range/detail/safe_bool.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
@@ -221,5 +221,3 @@ test-suite range :
|
||||
[ range-test value_type ]
|
||||
;
|
||||
|
||||
# `quick` target (for CI)
|
||||
alias quick : std_container ;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
#if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_RANGE_BASED_FOR)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
@@ -58,6 +59,76 @@ namespace
|
||||
test_push_back_impl< std::vector<std::size_t> >();
|
||||
test_push_back_impl< std::list<std::size_t> >();
|
||||
}
|
||||
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
// test type which is not copyable by moveable.
|
||||
class noncopyable_int : boost::noncopyable {
|
||||
private:
|
||||
int i;
|
||||
public:
|
||||
noncopyable_int(int x) : i(x) {}
|
||||
noncopyable_int(const noncopyable_int&) = delete;
|
||||
noncopyable_int& operator=(const noncopyable_int&) = delete;
|
||||
noncopyable_int(noncopyable_int&& o) : i(o.i) {}
|
||||
noncopyable_int& operator=(noncopyable_int&& o) { return o; }
|
||||
bool operator!=(const noncopyable_int &rhs) { return i != rhs.i; }
|
||||
friend std::ostream &operator<<(std::ostream &os, const noncopyable_int& x);
|
||||
};
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const noncopyable_int& x)
|
||||
{
|
||||
return os << x.i;
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_push_back_move_impl(std::size_t n)
|
||||
{
|
||||
Container test;
|
||||
Container reference;
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
reference.push_back(noncopyable_int(i));
|
||||
|
||||
{
|
||||
Container to_push_back;
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
to_push_back.push_back(noncopyable_int(i));
|
||||
|
||||
boost::push_back(test, std::move(to_push_back));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
// Do it again to push onto non-empty container
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
reference.push_back(noncopyable_int(i));
|
||||
|
||||
{
|
||||
Container to_push_back;
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
to_push_back.push_back(noncopyable_int(i));
|
||||
|
||||
boost::push_back(test, std::move(to_push_back));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_push_back_move_impl()
|
||||
{
|
||||
test_push_back_move_impl< Container >(0);
|
||||
test_push_back_move_impl< Container >(1);
|
||||
test_push_back_move_impl< Container >(2);
|
||||
test_push_back_move_impl< Container >(100);
|
||||
}
|
||||
|
||||
void test_push_back_move()
|
||||
{
|
||||
test_push_back_move_impl< std::vector<noncopyable_int> >();
|
||||
test_push_back_move_impl< std::list<noncopyable_int> >();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
@@ -67,6 +138,9 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.push_back" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_push_back ) );
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
test->add( BOOST_TEST_CASE( &test_push_back_move ) );
|
||||
#endif
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
@@ -18,23 +18,6 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// Test an integer range with a step size of 1.
|
||||
template<typename Integer>
|
||||
void test_irange_impl(Integer last)
|
||||
{
|
||||
std::vector<Integer> reference;
|
||||
for (Integer i = static_cast<Integer>(0); i < last; ++i)
|
||||
{
|
||||
reference.push_back(i);
|
||||
}
|
||||
|
||||
std::vector<Integer> test;
|
||||
boost::push_back(test, boost::irange(last));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
// Test an integer range with a step size of 1.
|
||||
template<typename Integer>
|
||||
void test_irange_impl(Integer first, Integer last)
|
||||
@@ -51,52 +34,36 @@ namespace boost
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
BOOST_ASSERT( step != 0 );
|
||||
|
||||
|
||||
// Skip tests that have negative values if the type is
|
||||
// unsigned
|
||||
if ((static_cast<IntegerInput>(static_cast<Integer>(first)) != first)
|
||||
|| (static_cast<IntegerInput>(static_cast<Integer>(last)) != last))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Integer> reference;
|
||||
|
||||
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;
|
||||
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;
|
||||
boost::push_back(test, boost::irange(first, last, step));
|
||||
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
// Test driver function that for an integer range [first, last)
|
||||
// drives the test implementation through various integer
|
||||
// types.
|
||||
void test_irange(int last)
|
||||
{
|
||||
test_irange_impl<signed char>(last);
|
||||
test_irange_impl<unsigned char>(last);
|
||||
test_irange_impl<signed short>(last);
|
||||
test_irange_impl<unsigned short>(last);
|
||||
test_irange_impl<signed int>(last);
|
||||
test_irange_impl<unsigned int>(last);
|
||||
test_irange_impl<signed long>(last);
|
||||
test_irange_impl<unsigned long>(last);
|
||||
}
|
||||
|
||||
|
||||
// Test driver function that for an integer range [first, last)
|
||||
// drives the test implementation through various integer
|
||||
// types.
|
||||
@@ -135,11 +102,6 @@ namespace boost
|
||||
// number of implementation branches.
|
||||
void irange_unit_test()
|
||||
{
|
||||
// Test the single-step version of irange(last)
|
||||
test_irange(0);
|
||||
test_irange(1);
|
||||
test_irange(10);
|
||||
|
||||
// Test the single-step version of irange(first, last)
|
||||
test_irange(0, 0);
|
||||
test_irange(0, 1);
|
||||
@@ -162,14 +124,14 @@ namespace boost
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user