forked from boostorg/range
[range] - merge the tested changes from the trunk in preparation for the 1.46 release.
[SVN r67905]
This commit is contained in:
1 parent
674be9dfa0
commit
6d46ce412f
143 files changed
+5587
-2015
No files matched your search
@@ -59,6 +59,8 @@ test-suite range :
|
||||
[ range-test adaptor_test/sliced_example ]
|
||||
[ range-test adaptor_test/strided_example ]
|
||||
[ range-test adaptor_test/transformed_example ]
|
||||
[ range-test adaptor_test/type_erased ]
|
||||
[ range-test adaptor_test/type_erased_example ]
|
||||
[ range-test adaptor_test/uniqued_example ]
|
||||
[ range-test algorithm_test/adjacent_find ]
|
||||
[ range-test algorithm_test/binary_search ]
|
||||
@@ -131,11 +133,13 @@ test-suite range :
|
||||
[ range-test algorithm_example ]
|
||||
[ range-test array ]
|
||||
# [ range-test atl : <include>$(VC71_ROOT)/atlmfc/include ]
|
||||
[ range-test begin ]
|
||||
[ range-test combine ]
|
||||
[ range-test compat2 ]
|
||||
[ range-test compat3 ]
|
||||
[ range-test const_ranges ]
|
||||
[ range-test counting_range ]
|
||||
[ range-test end ]
|
||||
[ range-test extension_mechanism ]
|
||||
[ range-test extension_size ]
|
||||
[ range-test has_range_iterator ]
|
||||
|
||||
@@ -128,10 +128,10 @@ namespace boost
|
||||
|
||||
typedef boost::strided_range<Container> strided_range_t;
|
||||
strided_range_t rng( boost::adaptors::stride(c, 0) );
|
||||
typedef typename boost::range_iterator<strided_range_t>::type iter_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<strided_range_t>::type iter_t;
|
||||
|
||||
iter_t first(boost::begin(c), 0, 0, boost::size(c));
|
||||
iter_t last(boost::end(c), 0, boost::size(c), boost::size(c));
|
||||
iter_t first(boost::begin(c), boost::begin(c), boost::end(c), 0);
|
||||
iter_t last(boost::begin(c), boost::end(c), boost::end(c), 0);
|
||||
|
||||
iter_t it = first;
|
||||
for (int i = 0; i < 10; ++i, ++it)
|
||||
@@ -206,16 +206,6 @@ namespace boost
|
||||
++(this->base_reference());
|
||||
}
|
||||
|
||||
bool equal(const strided_mock_iterator& other) const
|
||||
{
|
||||
return this->base() == other.base();
|
||||
}
|
||||
|
||||
BOOST_DEDUCED_TYPENAME super_t::reference dereference() const
|
||||
{
|
||||
return *(this->base());
|
||||
}
|
||||
|
||||
friend class boost::iterator_core_access;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,481 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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)
|
||||
//
|
||||
#include <boost/range/adaptor/type_erased.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
#include <boost/range/algorithm/fill.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost_range_adaptor_type_erased_test
|
||||
{
|
||||
class MockType
|
||||
{
|
||||
public:
|
||||
MockType()
|
||||
: m_x(0)
|
||||
{
|
||||
}
|
||||
|
||||
MockType(int x)
|
||||
: m_x(x)
|
||||
{
|
||||
}
|
||||
|
||||
int get() const { return m_x; }
|
||||
|
||||
inline bool operator==(const MockType& other) const
|
||||
{
|
||||
return m_x == other.m_x;
|
||||
}
|
||||
|
||||
inline bool operator!=(const MockType& other) const
|
||||
{
|
||||
return m_x != other.m_x;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_x;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const MockType& obj)
|
||||
{
|
||||
out << obj.get();
|
||||
return out;
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_type_erased_impl(Container& c)
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
typedef typename boost::adaptors::type_erased<> type_erased_t;
|
||||
|
||||
|
||||
std::vector<value_type> output;
|
||||
|
||||
boost::push_back(output, boost::adaptors::type_erase(c, type_erased_t()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( output.begin(), output.end(),
|
||||
c.begin(), c.end() );
|
||||
|
||||
output.clear();
|
||||
boost::push_back(output, c | type_erased_t());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( output.begin(), output.end(),
|
||||
c.begin(), c.end() );
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_const_and_mutable(Container& c)
|
||||
{
|
||||
test_type_erased_impl(c);
|
||||
|
||||
const Container& const_c = c;
|
||||
test_type_erased_impl(const_c);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_driver()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
|
||||
Container c;
|
||||
test_const_and_mutable(c);
|
||||
|
||||
c += value_type(1);
|
||||
test_const_and_mutable(c);
|
||||
|
||||
c += value_type(2);
|
||||
test_const_and_mutable(c);
|
||||
}
|
||||
|
||||
void test_type_erased()
|
||||
{
|
||||
test_driver< std::list<int> >();
|
||||
test_driver< std::vector<int> >();
|
||||
|
||||
test_driver< std::list<MockType> >();
|
||||
test_driver< std::vector<MockType> >();
|
||||
}
|
||||
|
||||
template<
|
||||
class Traversal
|
||||
, class Container
|
||||
>
|
||||
void test_writeable(Container&, boost::single_pass_traversal_tag)
|
||||
{}
|
||||
|
||||
template<
|
||||
class Traversal
|
||||
, class Container
|
||||
>
|
||||
void test_writeable(Container& source, boost::forward_traversal_tag)
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
typedef typename boost::range_difference<Container>::type difference_type;
|
||||
typedef typename boost::range_reference<Container>::type mutable_reference_type;
|
||||
typedef boost::any_range<
|
||||
value_type
|
||||
, Traversal
|
||||
, mutable_reference_type
|
||||
, difference_type
|
||||
> mutable_any_range;
|
||||
|
||||
mutable_any_range r = source | boost::adaptors::type_erased<>();
|
||||
std::vector<value_type> output_test;
|
||||
boost::fill(r, value_type(1));
|
||||
BOOST_CHECK_EQUAL( boost::distance(r), boost::distance(source) );
|
||||
std::vector<value_type> reference_output(source.size(), value_type(1));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_output.begin(), reference_output.end(),
|
||||
r.begin(), r.end() );
|
||||
|
||||
}
|
||||
|
||||
template<
|
||||
class Container
|
||||
, class Traversal
|
||||
, class Buffer
|
||||
>
|
||||
void test_type_erased_impl()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef Buffer buffer_type;
|
||||
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
|
||||
typedef typename boost::any_range_type_generator<
|
||||
Container
|
||||
, boost::use_default
|
||||
, Traversal
|
||||
, boost::use_default
|
||||
, boost::use_default
|
||||
, Buffer
|
||||
>::type mutable_any_range;
|
||||
|
||||
typedef typename boost::any_range_type_generator<
|
||||
const Container
|
||||
, boost::use_default
|
||||
, Traversal
|
||||
, boost::use_default
|
||||
, boost::use_default
|
||||
, Buffer
|
||||
>::type const_any_range;
|
||||
|
||||
typedef boost::adaptors::type_erased<
|
||||
boost::use_default
|
||||
, Traversal
|
||||
, boost::use_default
|
||||
, boost::use_default
|
||||
, Buffer
|
||||
> type_erased_t;
|
||||
|
||||
Container source;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
source.push_back(value_type(i));
|
||||
|
||||
mutable_any_range r(source);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||
r.begin(), r.end() );
|
||||
|
||||
r = mutable_any_range();
|
||||
BOOST_CHECK_EQUAL( r.empty(), true );
|
||||
|
||||
r = source | type_erased_t();
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||
r.begin(), r.end() );
|
||||
r = mutable_any_range();
|
||||
|
||||
r = boost::adaptors::type_erase(source, type_erased_t());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||
r.begin(), r.end() );
|
||||
r = mutable_any_range();
|
||||
|
||||
test_writeable<Traversal>(source, Traversal());
|
||||
|
||||
// convert and construct a const any_range from a mutable source
|
||||
// range
|
||||
const_any_range cr(source);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||
cr.begin(), cr.end() );
|
||||
// assign an empty range and ensure that this correctly results
|
||||
// in an empty range. This is important for the validity of
|
||||
// the rest of the tests.
|
||||
cr = const_any_range();
|
||||
BOOST_CHECK_EQUAL( cr.empty(), true );
|
||||
|
||||
// Test the pipe type_erased adaptor from a constant source
|
||||
// range to a constant any_range
|
||||
const Container& const_source = source;
|
||||
cr = const_any_range();
|
||||
cr = const_source | type_erased_t();
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
||||
cr.begin(), cr.end() );
|
||||
|
||||
// Test the pipe type erased adaptor from a mutable source
|
||||
// range to a constant any_range
|
||||
cr = const_any_range();
|
||||
cr = source | type_erased_t();
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||
cr.begin(), cr.end() );
|
||||
|
||||
// Use the function form of the type_erase adaptor from a constant
|
||||
// source range
|
||||
cr = const_any_range();
|
||||
cr = boost::adaptors::type_erase(const_source, type_erased_t());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
||||
cr.begin(), cr.end() );
|
||||
|
||||
// Assignment from mutable to const...
|
||||
cr = const_any_range();
|
||||
cr = r;
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cr.begin(), cr.end(),
|
||||
r.begin(), r.end() );
|
||||
|
||||
// Converting copy from mutable to const...
|
||||
cr = const_any_range();
|
||||
cr = const_any_range(r);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cr.begin(), cr.end(),
|
||||
r.begin(), r.end() );
|
||||
}
|
||||
|
||||
template<
|
||||
class Container
|
||||
, class Traversal
|
||||
, class Buffer
|
||||
>
|
||||
class test_type_erased_impl_fn
|
||||
{
|
||||
public:
|
||||
typedef void result_type;
|
||||
void operator()()
|
||||
{
|
||||
test_type_erased_impl< Container, Traversal, Buffer >();
|
||||
}
|
||||
};
|
||||
|
||||
template<
|
||||
class Container
|
||||
, class Traversal
|
||||
>
|
||||
void test_type_erased_exercise_buffer_types()
|
||||
{
|
||||
using boost::any_iterator_default_buffer;
|
||||
using boost::any_iterator_buffer;
|
||||
using boost::any_iterator_heap_only_buffer;
|
||||
using boost::any_iterator_stack_only_buffer;
|
||||
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_default_buffer >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_heap_only_buffer >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<1> >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<2> >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<32> >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<64> >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<128> >()();
|
||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_stack_only_buffer<128> >()();
|
||||
}
|
||||
|
||||
void test_type_erased_single_pass()
|
||||
{
|
||||
test_type_erased_exercise_buffer_types< std::list<int>, boost::single_pass_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<int>, boost::single_pass_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<int>, boost::single_pass_traversal_tag >();
|
||||
|
||||
test_type_erased_exercise_buffer_types< std::list<MockType>, boost::single_pass_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<MockType>, boost::single_pass_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<MockType>, boost::single_pass_traversal_tag >();
|
||||
}
|
||||
|
||||
void test_type_erased_forward()
|
||||
{
|
||||
test_type_erased_exercise_buffer_types< std::list<int>, boost::forward_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<int>, boost::forward_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<int>, boost::forward_traversal_tag >();
|
||||
|
||||
test_type_erased_exercise_buffer_types< std::list<MockType>, boost::forward_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<MockType>, boost::forward_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<MockType>, boost::forward_traversal_tag >();
|
||||
}
|
||||
|
||||
void test_type_erased_bidirectional()
|
||||
{
|
||||
test_type_erased_exercise_buffer_types< std::list<int>, boost::bidirectional_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<int>, boost::bidirectional_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<int>, boost::bidirectional_traversal_tag >();
|
||||
|
||||
test_type_erased_exercise_buffer_types< std::list<MockType>, boost::bidirectional_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::deque<MockType>, boost::bidirectional_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<MockType>, boost::bidirectional_traversal_tag >();
|
||||
}
|
||||
|
||||
void test_type_erased_random_access()
|
||||
{
|
||||
test_type_erased_exercise_buffer_types< std::deque<int>, boost::random_access_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<int>, boost::random_access_traversal_tag >();
|
||||
|
||||
test_type_erased_exercise_buffer_types< std::deque<MockType>, boost::random_access_traversal_tag >();
|
||||
test_type_erased_exercise_buffer_types< std::vector<MockType>, boost::random_access_traversal_tag >();
|
||||
}
|
||||
|
||||
void test_type_erased_multiple_different_template_parameter_conversion()
|
||||
{
|
||||
typedef boost::any_range<
|
||||
int
|
||||
, boost::random_access_traversal_tag
|
||||
, int&
|
||||
, std::ptrdiff_t
|
||||
> source_range_type;
|
||||
|
||||
typedef boost::any_range<
|
||||
int
|
||||
, boost::single_pass_traversal_tag
|
||||
, const int&
|
||||
, std::ptrdiff_t
|
||||
> target_range_type;
|
||||
|
||||
source_range_type source;
|
||||
|
||||
// Converting via construction
|
||||
target_range_type t1(source);
|
||||
|
||||
// Converting via assignment
|
||||
target_range_type t2;
|
||||
t2 = source;
|
||||
|
||||
// Converting via construction to a type with a reference type
|
||||
// that is a value
|
||||
typedef boost::any_range<
|
||||
int
|
||||
, boost::single_pass_traversal_tag
|
||||
, int
|
||||
, std::ptrdiff_t
|
||||
> target_range2_type;
|
||||
|
||||
target_range2_type t3(source);
|
||||
target_range2_type t4;
|
||||
t4 = source;
|
||||
}
|
||||
|
||||
template<
|
||||
class Traversal
|
||||
, class ValueType
|
||||
, class SourceValueType
|
||||
, class SourceReference
|
||||
, class TargetValueType
|
||||
, class TargetReference
|
||||
>
|
||||
void test_type_erased_mix_values_impl()
|
||||
{
|
||||
typedef std::vector< ValueType > Container;
|
||||
|
||||
typedef typename boost::any_range_type_generator<
|
||||
Container
|
||||
, SourceValueType
|
||||
, Traversal
|
||||
, SourceReference
|
||||
>::type source_type;
|
||||
|
||||
typedef typename boost::any_range_type_generator<
|
||||
Container
|
||||
, TargetValueType
|
||||
, Traversal
|
||||
, TargetReference
|
||||
>::type target_type;
|
||||
|
||||
Container test_data;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
test_data.push_back(i);
|
||||
|
||||
const source_type source_data(test_data);
|
||||
target_type t1(source_data);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source_data.begin(), source_data.end(),
|
||||
t1.begin(), t1.end() );
|
||||
|
||||
target_type t2;
|
||||
t2 = source_data;
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( source_data.begin(), source_data.end(),
|
||||
t2.begin(), t2.end() );
|
||||
}
|
||||
|
||||
template<class Traversal>
|
||||
void test_type_erased_mix_values_driver()
|
||||
{
|
||||
test_type_erased_mix_values_impl< Traversal, int, char, const int&, short, const int& >();
|
||||
test_type_erased_mix_values_impl< Traversal, int, int*, const int&, char, const int& >();
|
||||
test_type_erased_mix_values_impl< Traversal, MockType, char, const MockType&, short, const MockType& >();
|
||||
|
||||
// In fact value type should have no effect in the eligibility
|
||||
// for conversion, hence we should be able to convert it
|
||||
// completely backwards!
|
||||
test_type_erased_mix_values_impl< Traversal, int, short, const int&, char, const int& >();
|
||||
test_type_erased_mix_values_impl< Traversal, int, char, const int&, int*, const int& >();
|
||||
}
|
||||
|
||||
void test_type_erased_mix_values()
|
||||
{
|
||||
test_type_erased_mix_values_driver< boost::single_pass_traversal_tag >();
|
||||
test_type_erased_mix_values_driver< boost::forward_traversal_tag >();
|
||||
test_type_erased_mix_values_driver< boost::bidirectional_traversal_tag >();
|
||||
test_type_erased_mix_values_driver< boost::random_access_traversal_tag >();
|
||||
}
|
||||
|
||||
void test_type_erased_operator_brackets()
|
||||
{
|
||||
typedef boost::adaptors::type_erased<> type_erased_t;
|
||||
|
||||
std::vector<int> c;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
c.push_back(i);
|
||||
|
||||
typedef boost::any_range<
|
||||
int
|
||||
, boost::random_access_traversal_tag
|
||||
, int
|
||||
, boost::range_difference< std::vector<int> >::type
|
||||
, boost::use_default
|
||||
> any_range_type;
|
||||
|
||||
any_range_type rng = c | type_erased_t();
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( rng[i], i );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.type_erased" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_single_pass ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_forward ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_bidirectional ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_random_access ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_multiple_different_template_parameter_conversion ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_mix_values ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_adaptor_type_erased_test::test_type_erased_operator_brackets ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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/adaptor/type_erased.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace boost_range_test
|
||||
{
|
||||
namespace type_erased_example
|
||||
{
|
||||
|
||||
// The client interface from an OO perspective merely requires a sequence
|
||||
// of integers that can be forward traversed
|
||||
typedef boost::any_range<
|
||||
int
|
||||
, boost::forward_traversal_tag
|
||||
, int
|
||||
, std::ptrdiff_t
|
||||
> integer_range;
|
||||
|
||||
namespace server
|
||||
{
|
||||
void display_integers(const integer_range& rng)
|
||||
{
|
||||
boost::copy(rng,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
namespace client
|
||||
{
|
||||
void run()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
// Under most conditions one would simply use an appropriate
|
||||
// any_range as a function parameter. The type_erased adaptor
|
||||
// is often superfluous. However because the type_erased
|
||||
// adaptor is applied to a range, we can use default template
|
||||
// arguments that are generated in conjunction with the
|
||||
// range type to which we are applying the adaptor.
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5;
|
||||
|
||||
// Note that this call is to a non-template function
|
||||
server::display_integers(input);
|
||||
|
||||
std::list<int> input2;
|
||||
input2 += 6,7,8,9,10;
|
||||
|
||||
// Note that this call is to the same non-tempate function
|
||||
server::display_integers(input2);
|
||||
|
||||
input2.clear();
|
||||
input2 += 11,12,13,14,15;
|
||||
|
||||
// Calling using the adaptor looks like this:
|
||||
// Notice that here I have a type_erased that would be a
|
||||
// bidirectional_traversal_tag, but this is convertible
|
||||
// to the forward_traversal_tag equivalent hence this
|
||||
// works.
|
||||
server::display_integers(input2 | type_erased<>());
|
||||
|
||||
// However we may simply wish to define an adaptor that
|
||||
// takes a range and makes it into an appropriate
|
||||
// forward_traversal any_range...
|
||||
typedef boost::adaptors::type_erased<
|
||||
boost::use_default
|
||||
, boost::forward_traversal_tag
|
||||
> type_erased_forward;
|
||||
|
||||
// This adaptor can turn other containers with different
|
||||
// value_types and reference_types into the appropriate
|
||||
// any_range.
|
||||
|
||||
server::display_integers(input2 | type_erased_forward());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace type_erased_example
|
||||
} // namespace boost_range_test
|
||||
} // anonymous namespace
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.type_erased_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test::type_erased_example::client::run) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -33,6 +33,7 @@ namespace boost
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef equal_to_x<int> pred_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<BOOST_DEDUCED_TYPENAME Container::iterator>::difference_type diff_t;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
@@ -72,9 +73,9 @@ namespace boost
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, false_predicate()) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont), false_predicate()) );
|
||||
|
||||
BOOST_CHECK_EQUAL( boost::size(cont), boost::count_if(cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( boost::size(cont), boost::count_if(cref_cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( boost::size(cont), boost::count_if(boost::make_iterator_range(cont), true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(cref_cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(boost::make_iterator_range(cont), true_predicate()) );
|
||||
}
|
||||
|
||||
void test_count_if()
|
||||
|
||||
@@ -22,85 +22,82 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_find
|
||||
{
|
||||
namespace
|
||||
class find_test_policy
|
||||
{
|
||||
class find_test_policy
|
||||
public:
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find(cont, 3);
|
||||
iter_t result2 = boost::find(boost::make_iterator_range(cont), 3);
|
||||
BOOST_CHECK( result == result2 );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find(cont, 3);
|
||||
iter_t result2 = boost::find(boost::make_iterator_range(cont), 3);
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find<return_type>(cont, 3);
|
||||
result_t result2 = boost::find<return_type>(boost::make_iterator_range(cont), 3);
|
||||
BOOST_CHECK( result == result2 );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find<return_type>(cont, 3);
|
||||
result_t result2 = boost::find<return_type>(boost::make_iterator_range(cont), 3);
|
||||
BOOST_CHECK( result == result2 );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find(cont.begin(), cont.end(), 3);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_find_container()
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, find_test_policy());
|
||||
return std::find(cont.begin(), cont.end(), 3);
|
||||
}
|
||||
};
|
||||
|
||||
void test_find()
|
||||
{
|
||||
test_find_container< std::vector<int> >();
|
||||
test_find_container< std::list<int> >();
|
||||
test_find_container< std::deque<int> >();
|
||||
template<class Container>
|
||||
void test_find_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
test_find_container< const std::vector<int> >();
|
||||
test_find_container< const std::list<int> >();
|
||||
test_find_container< const std::deque<int> >();
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
std::vector<int> vi;
|
||||
const std::vector<int>& cvi = vi;
|
||||
std::vector<int>::const_iterator it = boost::find(vi, 0);
|
||||
std::vector<int>::const_iterator it2 = boost::find(cvi, 0);
|
||||
BOOST_CHECK( it == it2 );
|
||||
}
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, find_test_policy());
|
||||
}
|
||||
|
||||
void test_find()
|
||||
{
|
||||
test_find_container< std::vector<int> >();
|
||||
test_find_container< std::list<int> >();
|
||||
test_find_container< std::deque<int> >();
|
||||
|
||||
test_find_container< const std::vector<int> >();
|
||||
test_find_container< const std::list<int> >();
|
||||
test_find_container< const std::deque<int> >();
|
||||
|
||||
std::vector<int> vi;
|
||||
const std::vector<int>& cvi = vi;
|
||||
std::vector<int>::const_iterator it = boost::find(vi, 0);
|
||||
std::vector<int>::const_iterator it2 = boost::find(cvi, 0);
|
||||
BOOST_CHECK( it == it2 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +107,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find::test_find ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+139
-142
@@ -21,173 +21,170 @@
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_find_end
|
||||
{
|
||||
namespace
|
||||
template<class Container2>
|
||||
class find_end_test_policy
|
||||
{
|
||||
template<class Container2>
|
||||
class find_end_test_policy
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
container2_t cont() { return m_cont; }
|
||||
container2_t cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_end(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_end(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_end_pred_test_policy
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_end_pred_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t it = boost::find_end(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
return it;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t it = boost::find_end(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
return it;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_end_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_end_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_end_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
template<class Container1, class Container2>
|
||||
void test_find_end_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
void test_find_end()
|
||||
{
|
||||
test_find_end_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::list<int>, std::list<int> >();
|
||||
test_find_end_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_end()
|
||||
{
|
||||
test_find_end_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::list<int>, std::list<int> >();
|
||||
test_find_end_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +194,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_end ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_end::test_find_end ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -21,171 +21,168 @@
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_find_first_of
|
||||
{
|
||||
namespace
|
||||
template<class Container2>
|
||||
class find_first_of_test_policy
|
||||
{
|
||||
template<class Container2>
|
||||
class find_first_of_test_policy
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
container2_t& cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_first_of_pred_test_policy
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_first_of_pred_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_first_of_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_first_of_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_first_of_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
template<class Container1, class Container2>
|
||||
void test_find_first_of_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
void test_find_first_of()
|
||||
{
|
||||
test_find_first_of_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_first_of()
|
||||
{
|
||||
test_find_first_of_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +192,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_first_of::test_find_first_of ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -23,97 +23,94 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_find_if
|
||||
{
|
||||
namespace
|
||||
template<class UnaryPredicate>
|
||||
class find_if_test_policy
|
||||
{
|
||||
template<class UnaryPredicate>
|
||||
class find_if_test_policy
|
||||
{
|
||||
public:
|
||||
explicit find_if_test_policy(UnaryPredicate pred)
|
||||
: m_pred(pred) {}
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_if(cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(find_if_test_policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_if<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::find_if<return_type>(boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_if(cont.begin(), cont.end(), m_pred);
|
||||
}
|
||||
|
||||
UnaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
UnaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class UnaryPredicate>
|
||||
find_if_test_policy<UnaryPredicate>
|
||||
make_policy(UnaryPredicate pred)
|
||||
{
|
||||
return find_if_test_policy<UnaryPredicate>(pred);
|
||||
}
|
||||
public:
|
||||
explicit find_if_test_policy(UnaryPredicate pred)
|
||||
: m_pred(pred) {}
|
||||
|
||||
template<class Container>
|
||||
void test_find_if_container()
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_if(cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
void test_find_if()
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
test_find_if_container< std::vector<int> >();
|
||||
test_find_if_container< std::list<int> >();
|
||||
test_find_if_container< std::deque<int> >();
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(find_if_test_policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_if<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::find_if<return_type>(boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
test_find_if_container< const std::vector<int> >();
|
||||
test_find_if_container< const std::list<int> >();
|
||||
test_find_if_container< const std::deque<int> >();
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_if(cont.begin(), cont.end(), m_pred);
|
||||
}
|
||||
|
||||
UnaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
UnaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class UnaryPredicate>
|
||||
find_if_test_policy<UnaryPredicate>
|
||||
make_policy(UnaryPredicate pred)
|
||||
{
|
||||
return find_if_test_policy<UnaryPredicate>(pred);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_find_if_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
}
|
||||
|
||||
void test_find_if()
|
||||
{
|
||||
test_find_if_container< std::vector<int> >();
|
||||
test_find_if_container< std::list<int> >();
|
||||
test_find_if_container< std::deque<int> >();
|
||||
|
||||
test_find_if_container< const std::vector<int> >();
|
||||
test_find_if_container< const std::list<int> >();
|
||||
test_find_if_container< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +120,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_if ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_if::test_find_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+135
-139
@@ -22,164 +22,160 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_lower_bound
|
||||
{
|
||||
namespace
|
||||
class lower_bound_policy
|
||||
{
|
||||
class lower_bound_policy
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct lower_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5, m_pred);
|
||||
BOOST_CHECK( result == boost::lower_bound(
|
||||
boost::make_iterator_range(cont), 5, m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5, policy.pred());
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(
|
||||
cont.begin(), cont.end(), 5, m_pred);
|
||||
}
|
||||
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct lower_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5, m_pred);
|
||||
BOOST_CHECK( result == boost::lower_bound(
|
||||
boost::make_iterator_range(cont), 5, m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5, policy.pred());
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_lower_bound_impl()
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
return std::lower_bound(
|
||||
cont.begin(), cont.end(), 5, m_pred);
|
||||
}
|
||||
|
||||
void test_lower_bound()
|
||||
{
|
||||
test_lower_bound_impl< std::vector<int> >();
|
||||
test_lower_bound_impl< std::list<int> >();
|
||||
test_lower_bound_impl< std::deque<int> >();
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
test_lower_bound_impl< const std::vector<int> >();
|
||||
test_lower_bound_impl< const std::list<int> >();
|
||||
test_lower_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_lower_bound_impl()
|
||||
{
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_lower_bound()
|
||||
{
|
||||
test_lower_bound_impl< std::vector<int> >();
|
||||
test_lower_bound_impl< std::list<int> >();
|
||||
test_lower_bound_impl< std::deque<int> >();
|
||||
|
||||
test_lower_bound_impl< const std::vector<int> >();
|
||||
test_lower_bound_impl< const std::list<int> >();
|
||||
test_lower_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_lower_bound::test_lower_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+105
-108
@@ -22,134 +22,131 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_max_element
|
||||
{
|
||||
namespace
|
||||
class max_element_test_policy
|
||||
{
|
||||
class max_element_test_policy
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont);
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont);
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::max_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class max_element_pred_test_policy
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
return std::max_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class max_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::max_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_max_element_impl(TestPolicy policy)
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
return std::max_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_max_element_impl()
|
||||
{
|
||||
test_max_element_impl<Container>(max_element_test_policy());
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::less<int> >());
|
||||
template<class Container, class TestPolicy>
|
||||
void test_max_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
void test_max_element()
|
||||
{
|
||||
test_max_element_impl< const std::vector<int> >();
|
||||
test_max_element_impl< const std::deque<int> >();
|
||||
test_max_element_impl< const std::list<int> >();
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
test_max_element_impl< std::vector<int> >();
|
||||
test_max_element_impl< std::deque<int> >();
|
||||
test_max_element_impl< std::list<int> >();
|
||||
}
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_max_element_impl()
|
||||
{
|
||||
test_max_element_impl<Container>(max_element_test_policy());
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::less<int> >());
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
|
||||
void test_max_element()
|
||||
{
|
||||
test_max_element_impl< const std::vector<int> >();
|
||||
test_max_element_impl< const std::deque<int> >();
|
||||
test_max_element_impl< const std::list<int> >();
|
||||
|
||||
test_max_element_impl< std::vector<int> >();
|
||||
test_max_element_impl< std::deque<int> >();
|
||||
test_max_element_impl< std::list<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +156,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_max_element ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_max_element::test_max_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+104
-107
@@ -22,132 +22,129 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_min_element
|
||||
{
|
||||
namespace
|
||||
class min_element_test_policy
|
||||
{
|
||||
class min_element_test_policy
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont);
|
||||
BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont);
|
||||
BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::min_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class min_element_pred_test_policy
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
return std::min_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class min_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::min_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::min_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::min_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_min_element_impl(TestPolicy policy)
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
return std::min_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_min_element_impl()
|
||||
{
|
||||
test_min_element_impl<Container>(min_element_test_policy());
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::less<int> >());
|
||||
template<class Container, class TestPolicy>
|
||||
void test_min_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
void test_min_element()
|
||||
{
|
||||
test_min_element_impl< const std::vector<int> >();
|
||||
test_min_element_impl< const std::deque<int> >();
|
||||
test_min_element_impl< const std::list<int> >();
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
test_min_element_impl< std::vector<int> >();
|
||||
test_min_element_impl< std::deque<int> >();
|
||||
test_min_element_impl< std::list<int> >();
|
||||
}
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_min_element_impl()
|
||||
{
|
||||
test_min_element_impl<Container>(min_element_test_policy());
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::less<int> >());
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
|
||||
void test_min_element()
|
||||
{
|
||||
test_min_element_impl< const std::vector<int> >();
|
||||
test_min_element_impl< const std::deque<int> >();
|
||||
test_min_element_impl< const std::list<int> >();
|
||||
|
||||
test_min_element_impl< std::vector<int> >();
|
||||
test_min_element_impl< std::deque<int> >();
|
||||
test_min_element_impl< std::list<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +154,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_min_element ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_min_element::test_min_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -21,109 +21,106 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_partition
|
||||
{
|
||||
namespace
|
||||
struct equal_to_5
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class partition_test_policy
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
|
||||
const Container old_cont(cont);
|
||||
Container cont2(old_cont);
|
||||
iter_t result = boost::partition(cont, UnaryPredicate());
|
||||
|
||||
boost::partition(cont2, UnaryPredicate());
|
||||
cont2 = old_cont;
|
||||
boost::partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
const Container old_cont(cont);
|
||||
Container cont2(old_cont);
|
||||
iter_t result = boost::partition(cont, UnaryPredicate());
|
||||
result_t result = boost::partition<return_type>(cont, policy.pred());
|
||||
|
||||
boost::partition(cont2, UnaryPredicate());
|
||||
cont2 = old_cont;
|
||||
boost::partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
// Test that operation a temporary created by using
|
||||
// make_iterator_range.
|
||||
boost::partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
|
||||
const Container old_cont(cont);
|
||||
Container cont2(old_cont);
|
||||
result_t result = boost::partition<return_type>(cont, policy.pred());
|
||||
|
||||
// Test that operation a temporary created by using
|
||||
// make_iterator_range.
|
||||
boost::partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_partition_impl()
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
return std::partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
void test_partition()
|
||||
{
|
||||
test_partition_impl< std::vector<int> >();
|
||||
test_partition_impl< std::list<int> >();
|
||||
test_partition_impl< std::deque<int> >();
|
||||
}
|
||||
template<class Container>
|
||||
void test_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_partition()
|
||||
{
|
||||
test_partition_impl< std::vector<int> >();
|
||||
test_partition_impl< std::list<int> >();
|
||||
test_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +130,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_partition ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_partition::test_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -21,116 +21,112 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_stable_partition
|
||||
{
|
||||
namespace
|
||||
struct equal_to_5
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class stable_partition_test_policy
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class stable_partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
Container cont2(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::stable_partition(cont, UnaryPredicate());
|
||||
|
||||
iter_t temp_result = boost::stable_partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
|
||||
std::distance(cont2.begin(), temp_result) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
Container cont2(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::stable_partition(cont, UnaryPredicate());
|
||||
|
||||
iter_t temp_result = boost::stable_partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
|
||||
std::distance(cont2.begin(), temp_result) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
result_t result = boost::stable_partition<return_type>(cont, policy.pred());
|
||||
|
||||
result_t result2 = boost::stable_partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
|
||||
cont.begin(), cont.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
Container cont2(cont);
|
||||
result_t result = boost::stable_partition<return_type>(cont, policy.pred());
|
||||
|
||||
result_t result2 = boost::stable_partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
|
||||
cont.begin(), cont.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_stable_partition_impl()
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
stable_partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
void test_stable_partition()
|
||||
{
|
||||
test_stable_partition_impl< std::vector<int> >();
|
||||
test_stable_partition_impl< std::list<int> >();
|
||||
test_stable_partition_impl< std::deque<int> >();
|
||||
}
|
||||
template<class Container>
|
||||
void test_stable_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
stable_partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_stable_partition()
|
||||
{
|
||||
test_stable_partition_impl< std::vector<int> >();
|
||||
test_stable_partition_impl< std::list<int> >();
|
||||
test_stable_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_stable_partition::test_stable_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+126
-129
@@ -23,156 +23,153 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_unique
|
||||
{
|
||||
namespace
|
||||
// test the 'unique' algorithm without a predicate
|
||||
class unique_test_policy
|
||||
{
|
||||
// test the 'unique' algorithm without a predicate
|
||||
class unique_test_policy
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont);
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont);
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// test the 'unique' algorithm with a predicate
|
||||
template<class Pred>
|
||||
class unique_pred_test_policy
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
// test the 'unique' algorithm with a predicate
|
||||
template<class Pred>
|
||||
class unique_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont, policy.pred());
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont, policy.pred());
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy, class Pred>
|
||||
void test_unique_impl(TestPolicy policy, Pred pred)
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_unique_impl()
|
||||
{
|
||||
test_unique_impl<Container>(
|
||||
unique_test_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
template<class Container, class TestPolicy, class Pred>
|
||||
void test_unique_impl(TestPolicy policy, Pred pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
void test_unique()
|
||||
{
|
||||
test_unique_impl< std::vector<int> >();
|
||||
test_unique_impl< std::list<int> >();
|
||||
test_unique_impl< std::deque<int> >();
|
||||
}
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_unique_impl()
|
||||
{
|
||||
test_unique_impl<Container>(
|
||||
unique_test_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_unique()
|
||||
{
|
||||
test_unique_impl< std::vector<int> >();
|
||||
test_unique_impl< std::list<int> >();
|
||||
test_unique_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +179,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_unique ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_unique::test_unique ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+128
-131
@@ -21,144 +21,141 @@
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
namespace boost_range_test_algorithm_upper_bound
|
||||
{
|
||||
namespace
|
||||
class upper_bound_policy
|
||||
{
|
||||
class upper_bound_policy
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type result_t;
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct upper_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5, BinaryPredicate());
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type result_t;
|
||||
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5, policy.pred());
|
||||
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(
|
||||
cont.begin(), cont.end(), 5, BinaryPredicate());
|
||||
}
|
||||
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct upper_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5, BinaryPredicate());
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
|
||||
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5, policy.pred());
|
||||
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_upper_bound_impl()
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
return std::upper_bound(
|
||||
cont.begin(), cont.end(), 5, BinaryPredicate());
|
||||
}
|
||||
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_upper_bound_impl()
|
||||
{
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_upper_bound()
|
||||
@@ -179,7 +176,7 @@ init_unit_test_suite(int argc, char* argv[])
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_upper_bound::test_upper_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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/detail/workaround.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# pragma warn -8091 // supress warning in Boost.Test
|
||||
# pragma warn -8057 // unused argument argc/argv in Boost.Test
|
||||
#endif
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
namespace mock_std
|
||||
{
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<SinglePassRange>::type
|
||||
begin(SinglePassRange& rng)
|
||||
{
|
||||
return rng.begin();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const SinglePassRange>::type
|
||||
begin(const SinglePassRange& rng)
|
||||
{
|
||||
return rng.begin();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void mock_algorithm_using_begin(const SinglePassRange& rng)
|
||||
{
|
||||
BOOST_CHECK( begin(rng) == rng.begin() );
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void mock_algorithm_using_begin(SinglePassRange& rng)
|
||||
{
|
||||
BOOST_CHECK( begin(rng) == rng.begin() );
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
#ifdef BOOST_RANGE_SIMULATE_BEGIN_WITHOUT_ADL_NAMESPACE_BARRIER
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type
|
||||
begin(SinglePassRange& rng)
|
||||
{
|
||||
return rng.begin();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type
|
||||
begin(const SinglePassRange& rng)
|
||||
{
|
||||
return rng.begin();
|
||||
}
|
||||
#endif
|
||||
|
||||
class MockTestBeginCollection
|
||||
{
|
||||
public:
|
||||
typedef char value_type;
|
||||
typedef const char* const_pointer;
|
||||
typedef char* pointer;
|
||||
typedef const_pointer const_iterator;
|
||||
typedef pointer iterator;
|
||||
|
||||
MockTestBeginCollection()
|
||||
: m_first()
|
||||
, m_last()
|
||||
{
|
||||
}
|
||||
|
||||
const_iterator begin() const { return m_first; }
|
||||
iterator begin() { return m_first; }
|
||||
const_iterator end() const { return m_last; }
|
||||
iterator end() { return m_last; }
|
||||
|
||||
private:
|
||||
iterator m_first;
|
||||
iterator m_last;
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void test_range_begin()
|
||||
{
|
||||
boost::MockTestBeginCollection c;
|
||||
const boost::MockTestBeginCollection& const_c = c;
|
||||
mock_std::mock_algorithm_using_begin(const_c);
|
||||
mock_std::mock_algorithm_using_begin(c);
|
||||
}
|
||||
}
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
boost::unit_test_framework::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" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_range_begin ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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/detail/workaround.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# pragma warn -8091 // supress warning in Boost.Test
|
||||
# pragma warn -8057 // unused argument argc/argv in Boost.Test
|
||||
#endif
|
||||
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
namespace mock_std
|
||||
{
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<SinglePassRange>::type
|
||||
end(SinglePassRange& rng)
|
||||
{
|
||||
return rng.end();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const SinglePassRange>::type
|
||||
end(const SinglePassRange& rng)
|
||||
{
|
||||
return rng.end();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void mock_algorithm_using_end(const SinglePassRange& rng)
|
||||
{
|
||||
BOOST_CHECK( end(rng) == rng.end() );
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void mock_algorithm_using_end(SinglePassRange& rng)
|
||||
{
|
||||
BOOST_CHECK( end(rng) == rng.end() );
|
||||
}
|
||||
}
|
||||
|
||||
namespace boost
|
||||
{
|
||||
#ifdef BOOST_RANGE_SIMULATE_END_WITHOUT_ADL_NAMESPACE_BARRIER
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type
|
||||
end(SinglePassRange& rng)
|
||||
{
|
||||
return rng.end();
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type
|
||||
end(const SinglePassRange& rng)
|
||||
{
|
||||
return rng.end();
|
||||
}
|
||||
#endif
|
||||
|
||||
class MockTestEndCollection
|
||||
{
|
||||
public:
|
||||
typedef char value_type;
|
||||
typedef const char* const_pointer;
|
||||
typedef char* pointer;
|
||||
typedef const_pointer const_iterator;
|
||||
typedef pointer iterator;
|
||||
|
||||
MockTestEndCollection()
|
||||
: m_first()
|
||||
, m_last()
|
||||
{
|
||||
}
|
||||
|
||||
const_iterator begin() const { return m_first; }
|
||||
iterator begin() { return m_first; }
|
||||
const_iterator end() const { return m_last; }
|
||||
iterator end() { return m_last; }
|
||||
|
||||
private:
|
||||
iterator m_first;
|
||||
iterator m_last;
|
||||
};
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void test_range_end_adl_avoidance()
|
||||
{
|
||||
boost::MockTestEndCollection c;
|
||||
const boost::MockTestEndCollection& const_c = c;
|
||||
mock_std::mock_algorithm_using_end(const_c);
|
||||
mock_std::mock_algorithm_using_end(c);
|
||||
}
|
||||
}
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
boost::unit_test_framework::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" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_range_end_adl_avoidance ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
+10
-42
@@ -24,24 +24,24 @@
|
||||
|
||||
namespace boost_range_extension_size_test
|
||||
{
|
||||
class FooWithoutMemberSize
|
||||
class FooWithoutSize
|
||||
{
|
||||
typedef std::list<int> impl_t;
|
||||
typedef impl_t::const_iterator const_iterator;
|
||||
typedef impl_t::iterator iterator;
|
||||
|
||||
public:
|
||||
friend inline const_iterator range_begin(const FooWithoutMemberSize& obj) { return obj.m_impl.begin(); }
|
||||
friend inline iterator range_begin(FooWithoutMemberSize& obj) { return obj.m_impl.begin(); }
|
||||
friend inline const_iterator range_end(const FooWithoutMemberSize& obj) { return obj.m_impl.end(); }
|
||||
friend inline iterator range_end(FooWithoutMemberSize& obj){ return obj.m_impl.end(); }
|
||||
friend inline const_iterator range_begin(const FooWithoutSize& obj) { return obj.m_impl.begin(); }
|
||||
friend inline iterator range_begin(FooWithoutSize& obj) { return obj.m_impl.begin(); }
|
||||
friend inline const_iterator range_end(const FooWithoutSize& obj) { return obj.m_impl.end(); }
|
||||
friend inline iterator range_end(FooWithoutSize& obj){ return obj.m_impl.end(); }
|
||||
|
||||
private:
|
||||
impl_t m_impl;
|
||||
};
|
||||
|
||||
boost::range_difference<std::list<int> >::type
|
||||
inline range_calculate_size(const FooWithoutMemberSize& rng)
|
||||
inline boost::range_difference<std::list<int> >::type
|
||||
range_calculate_size(const FooWithoutSize& rng)
|
||||
{
|
||||
return 2u;
|
||||
}
|
||||
@@ -49,12 +49,12 @@ namespace boost_range_extension_size_test
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<> struct range_iterator<const ::boost_range_extension_size_test::FooWithoutMemberSize>
|
||||
template<> struct range_iterator<const ::boost_range_extension_size_test::FooWithoutSize>
|
||||
{
|
||||
typedef std::list<int>::const_iterator type;
|
||||
};
|
||||
|
||||
template<> struct range_iterator< ::boost_range_extension_size_test::FooWithoutMemberSize >
|
||||
template<> struct range_iterator< ::boost_range_extension_size_test::FooWithoutSize>
|
||||
{
|
||||
typedef std::list<int>::iterator type;
|
||||
};
|
||||
@@ -63,13 +63,6 @@ namespace boost
|
||||
namespace
|
||||
{
|
||||
|
||||
void check_size_works_with_less_than_random_access()
|
||||
{
|
||||
std::list<int> container;
|
||||
container.push_back(1);
|
||||
BOOST_CHECK_EQUAL( boost::size(container), 1u );
|
||||
}
|
||||
|
||||
void check_size_works_with_random_access()
|
||||
{
|
||||
std::vector<int> container;
|
||||
@@ -77,28 +70,9 @@ void check_size_works_with_random_access()
|
||||
BOOST_CHECK_EQUAL( boost::size(container), 1u );
|
||||
}
|
||||
|
||||
class FooWithMemberSize
|
||||
{
|
||||
public:
|
||||
typedef std::list<int> impl_t;
|
||||
typedef impl_t::const_iterator const_iterator;
|
||||
typedef impl_t::iterator iterator;
|
||||
typedef impl_t::value_type value_type;
|
||||
|
||||
std::size_t size() const { return 1u; }
|
||||
const_iterator begin() const { return m_impl.begin(); }
|
||||
iterator begin() { return m_impl.begin(); }
|
||||
const_iterator end() const { return m_impl.end(); }
|
||||
iterator end() { return m_impl.end(); }
|
||||
|
||||
private:
|
||||
std::list<int> m_impl;
|
||||
};
|
||||
|
||||
void check_extension_size()
|
||||
{
|
||||
BOOST_CHECK_EQUAL( boost::size(FooWithMemberSize()), 1u );
|
||||
BOOST_CHECK_EQUAL( boost::size(boost_range_extension_size_test::FooWithoutMemberSize()), 2u );
|
||||
BOOST_CHECK_EQUAL( boost::size(boost_range_extension_size_test::FooWithoutSize()), 2u );
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@@ -109,14 +83,8 @@ test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_size_works_with_less_than_random_access ));
|
||||
test->add( BOOST_TEST_CASE( &check_size_works_with_random_access ));
|
||||
test->add( BOOST_TEST_CASE( &check_extension_size ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user