Boost.Range merge from trunk to release.

This is motivated by the need to correct the istream_range, to correct the adaptors.hpp header file, and correct the return types of various range algorithms.

[SVN r61517]
This commit is contained in:
Neil Groves
2010-04-23 22:50:56 +00:00
parent dfc30e334d
commit a47f15a98f
223 changed files with 2754 additions and 2666 deletions
+3
View File
@@ -42,6 +42,7 @@ test-suite range :
[ range-test adaptor_test/reversed ]
[ range-test adaptor_test/sliced ]
[ range-test adaptor_test/strided ]
[ range-test adaptor_test/strided2 ]
[ range-test adaptor_test/tokenized ]
[ range-test adaptor_test/transformed ]
[ range-test adaptor_test/uniqued ]
@@ -128,11 +129,13 @@ test-suite range :
[ range-test counting_range ]
[ range-test extension_mechanism ]
[ range-test irange ]
[ range-test istream_range ]
[ range-test iterator_pair ]
[ range-test iterator_range ]
# [ range-test mfc : <include>$(VC71_ROOT)/atlmfc/include ]
[ range-test join ]
[ range-test partial_workaround ]
[ range-test pointer_as_iterator ]
[ range-test reversible_range ]
[ range-test std_container ]
[ range-test string ]
@@ -55,4 +55,4 @@ init_unit_test_suite(int argc, char* argv[])
test->add( BOOST_TEST_CASE( &adjacent_filtered_example_test ) );
return test;
}
}
+1 -1
View File
@@ -55,4 +55,4 @@ init_unit_test_suite(int argc, char* argv[])
test->add( BOOST_TEST_CASE( &copied_example_test ) );
return test;
}
}
+67
View File
@@ -0,0 +1,67 @@
// 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/
//
// This test was added due to a report that the Range Adaptors:
// 1. Caused havoc when using namespace boost::adaptors was used
// 2. Did not work with non-member functions
// 3. The strided adaptor could not be composed with sliced
//
// None of these issues could be reproduced on GCC 4.4, but this
// work makes for useful additional test coverage since this
// uses chaining of adaptors and non-member functions whereas
// most of the tests avoid this use case.
#include <boost/range/adaptor/strided.hpp>
#include <boost/range/adaptor/sliced.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/irange.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <algorithm>
#include <vector>
namespace boost
{
namespace
{
int times_two(int x) { return x * 2; }
void strided_test2()
{
using namespace boost::adaptors;
using namespace boost::assign;
std::vector<int> v;
boost::push_back(v, boost::irange(0,10));
std::vector<int> z;
boost::push_back(z, v | sliced(2,6) | strided(2) | transformed(&times_two));
std::vector<int> reference;
reference += 4,8;
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
z.begin(), z.end() );
}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.strided2" );
test->add( BOOST_TEST_CASE( &boost::strided_test2 ) );
return test;
}
+16 -3
View File
@@ -21,6 +21,15 @@
namespace
{
struct DoubleValue
{
template< class Value >
Value operator()(Value x)
{
return x * 2;
}
};
template< class Container >
void test_push_front_impl(std::size_t n)
{
@@ -34,10 +43,14 @@ namespace
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
test.begin(), test.end() );
// Do it again to push onto non-empty container
reference.insert(reference.begin(), reference.begin(), reference.end());
// copy the orignal reference sequence
Container reference_copy(reference);
std::transform(reference.begin(), reference.end(), reference.begin(), DoubleValue());
boost::push_front(test, boost::irange<std::size_t>(0, n));
// Do it again to push onto non-empty container
reference.insert(reference.end(), reference_copy.begin(), reference_copy.end());
boost::push_front(test, boost::irange<std::size_t>(0, n * 2, 2));
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
test.begin(), test.end() );
+10 -10
View File
@@ -36,16 +36,16 @@ namespace boost
return boost::find(cont, 3);
}
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)
{
return boost::find<return_type>(cont, 3);
}
};
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)
{
return boost::find<return_type>(cont, 3);
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
+19 -19
View File
@@ -35,7 +35,7 @@ namespace boost
{
}
container2_t cont() { return m_cont; }
container2_t cont() { return m_cont; }
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -45,14 +45,14 @@ namespace boost
}
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)
{
return boost::find_end<return_type>(cont, policy.cont());
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::find_end<return_type>(cont, policy.cont());
}
};
template<class Container>
@@ -77,8 +77,8 @@ namespace boost
{
}
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -88,14 +88,14 @@ namespace boost
}
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)
{
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
}
};
template<class Container>
+19 -19
View File
@@ -35,7 +35,7 @@ namespace boost
{
}
container2_t& cont() { return m_cont; }
container2_t& cont() { return m_cont; }
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -45,14 +45,14 @@ namespace boost
}
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)
{
return boost::find_first_of<return_type>(cont, policy.cont());
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::find_first_of<return_type>(cont, policy.cont());
}
};
template<class Container>
@@ -77,8 +77,8 @@ namespace boost
{
}
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -88,14 +88,14 @@ namespace boost
}
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)
{
return boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
}
};
template<class Container>
+10 -10
View File
@@ -41,15 +41,15 @@ namespace boost
return boost::find_if(cont, m_pred);
}
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)
{
return boost::find_if<return_type>(cont, policy.pred());
}
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)
{
return boost::find_if<return_type>(cont, policy.pred());
}
};
template<class Container>
@@ -59,7 +59,7 @@ namespace boost
return std::find_if(cont.begin(), cont.end(), m_pred);
}
UnaryPredicate& pred() { return m_pred; }
UnaryPredicate& pred() { return m_pred; }
private:
UnaryPredicate m_pred;
+1 -1
View File
@@ -83,4 +83,4 @@ init_unit_test_suite(int argc, char* argv[])
test->add( BOOST_TEST_CASE( &boost::test_for_each ) );
return test;
}
}
+22 -22
View File
@@ -36,16 +36,16 @@ namespace boost
return boost::lower_bound(cont, 5);
}
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)
{
return boost::lower_bound<return_type>(cont, 5);
}
};
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)
{
return boost::lower_bound<return_type>(cont, 5);
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -66,15 +66,15 @@ namespace boost
}
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)
{
return boost::lower_bound<return_type>(
cont, 5, policy.pred());
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::lower_bound<return_type>(
cont, 5, policy.pred());
}
};
template<class Container>
@@ -85,10 +85,10 @@ namespace boost
cont.begin(), cont.end(), 5, m_pred);
}
BinaryPredicate& pred() { return m_pred; }
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
private:
BinaryPredicate m_pred;
};
template<class Container,
+17 -17
View File
@@ -37,14 +37,14 @@ namespace boost
}
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)
{
return boost::max_element<return_type>(cont);
}
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
return boost::max_element<return_type>(cont);
}
};
template< class Container >
@@ -66,17 +66,17 @@ namespace boost
return boost::max_element(cont, Pred());
}
Pred pred() const { return Pred(); }
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)
{
return boost::max_element<return_type>(cont, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::max_element<return_type>(cont, policy.pred());
}
};
template< class Container >
+17 -17
View File
@@ -37,14 +37,14 @@ namespace boost
}
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)
{
return boost::min_element<return_type>(cont);
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
return boost::min_element<return_type>(cont);
}
};
template< class Container >
@@ -66,17 +66,17 @@ namespace boost
return boost::min_element(cont, Pred());
}
Pred pred() const { return Pred(); }
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)
{
return boost::min_element<return_type>(cont, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::min_element<return_type>(cont, policy.pred());
}
};
template< class Container >
+9 -9
View File
@@ -44,17 +44,17 @@ namespace boost
return boost::partition(cont, UnaryPredicate());
}
UnaryPredicate pred() const { return UnaryPredicate(); }
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)
{
return boost::partition<return_type>(cont, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::partition<return_type>(cont, policy.pred());
}
};
template< class Container >
+9 -9
View File
@@ -44,17 +44,17 @@ namespace boost
return boost::stable_partition(cont, UnaryPredicate());
}
UnaryPredicate pred() const { return UnaryPredicate(); }
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)
{
return boost::stable_partition<return_type>(cont, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::stable_partition<return_type>(cont, policy.pred());
}
};
template< class Container >
+17 -17
View File
@@ -41,14 +41,14 @@ namespace boost
}
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)
{
return boost::unique<return_type>(cont);
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
return boost::unique<return_type>(cont);
}
};
template< class Container >
@@ -73,17 +73,17 @@ namespace boost
return std::unique(cont.begin(), cont.end(), Pred());
}
Pred pred() const { return Pred(); }
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)
{
return boost::unique<return_type>(cont, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::unique<return_type>(cont, policy.pred());
}
};
template< class Container >
+24 -24
View File
@@ -35,16 +35,16 @@ namespace boost
return boost::upper_bound(cont, 5);
}
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)
{
return boost::upper_bound<result_type>(cont, 5);
}
};
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)
{
return boost::upper_bound<result_type>(cont, 5);
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
@@ -65,15 +65,15 @@ namespace boost
}
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)
{
return boost::upper_bound<result_type>(
cont, 5, policy.pred());
}
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
operator()(Policy& policy, Container& cont)
{
return boost::upper_bound<result_type>(
cont, 5, policy.pred());
}
};
template<class Container>
@@ -83,11 +83,11 @@ namespace boost
return std::upper_bound(
cont.begin(), cont.end(), 5, BinaryPredicate());
}
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
};
template<class Container,
+1 -1
View File
@@ -70,4 +70,4 @@ init_unit_test_suite(int argc, char* argv[])
test->add( BOOST_TEST_CASE( &boost::counting_range_test ) );
return test;
}
}
+51
View File
@@ -0,0 +1,51 @@
// 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/istream_range.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <sstream>
#include <vector>
namespace
{
// Test an integer range with a step size of 1.
void test_istream_range()
{
std::stringstream s;
std::vector<int> reference;
for (int i = 0; i < 10; ++i)
{
reference.push_back(i);
s << i << " ";
}
std::vector<int> target;
boost::push_back(target, boost::range::istream_range<int>(s));
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
target.begin(), target.end() );
}
} // namespace 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.istream_range" );
test->add(BOOST_TEST_CASE( &test_istream_range ));
return test;
}
+1 -1
View File
@@ -61,7 +61,7 @@ void check_iterator_range()
BOOST_CHECK_EQUAL( r2.size(), size( r2 ) );
BOOST_CHECK_EQUAL( std::distance( r.begin(), r.end() ),
std::distance( boost::begin( r2 ), boost::end( r2 ) ) );
std::distance( boost::begin( r2 ), boost::end( r2 ) ) );
std::cout << r << r2;
+39
View File
@@ -0,0 +1,39 @@
// 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/iterator_range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/array.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <vector>
namespace
{
void test_pointer_as_iterator()
{
boost::array<int,3> arr;
boost::iterator_range<const int*> r(arr.begin(), arr.end());
r[0];
}
} // 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.pointer_as_iterator" );
test->add(BOOST_TEST_CASE( &test_pointer_as_iterator ));
return test;
}
+15 -15
View File
@@ -379,25 +379,25 @@ namespace boost
range_result, reference_it);
}
template< range_return_value result_type, class Container, class TestPolicy >
struct test_range
{
void operator()(Container& cont, TestPolicy policy)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
typedef BOOST_DEDUCED_TYPENAME range_return<Container, result_type>::type range_return_t;
typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range<result_type> test_range_t;
template< range_return_value result_type, class Container, class TestPolicy >
struct test_range
{
void operator()(Container& cont, TestPolicy policy)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
typedef BOOST_DEDUCED_TYPENAME range_return<Container, result_type>::type range_return_t;
typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range<result_type> test_range_t;
Container reference(cont);
Container test_cont(cont);
Container reference(cont);
Container test_cont(cont);
range_return_t range_result = test_range_t()(policy, test_cont);
iterator_t reference_it = policy.reference(reference);
range_return_t range_result = test_range_t()(policy, test_cont);
iterator_t reference_it = policy.reference(reference);
check_results<result_type>::check(test_cont, reference,
check_results<result_type>::check(test_cont, reference,
range_result, reference_it);
}
};
}
};
};
}
}