[boost][range] - merge from trunk of miscellaneous defect fixes

[SVN r72427]
This commit is contained in:
Neil Groves committed 2011-06-05 21:47:57 +00:00
commit 2f3d82be9f
28 files changed
+721 -147

No files matched your search

+20
View File
@@ -31,6 +31,22 @@ rule range-test ( name : includes * )
}
test-suite range :
[ compile ../doc/reference/adaptors/examples/adjacent_filtered.cpp : : example_adjacent_filtered ]
[ compile ../doc/reference/adaptors/examples/copied.cpp : : example_copied ]
[ compile ../doc/reference/adaptors/examples/filtered.cpp : : example_filtered ]
[ compile ../doc/reference/adaptors/examples/indexed.cpp : : example_indexed ]
[ compile ../doc/reference/adaptors/examples/indirected.cpp : : example_indirected ]
[ compile ../doc/reference/adaptors/examples/map_keys.cpp : : example_map_keys ]
[ compile ../doc/reference/adaptors/examples/map_values.cpp : : example_map_values ]
[ compile ../doc/reference/adaptors/examples/replaced.cpp : : example_replaced ]
[ compile ../doc/reference/adaptors/examples/replaced_if.cpp : : example_replaced_if ]
[ compile ../doc/reference/adaptors/examples/reversed.cpp : : example_reversed ]
[ compile ../doc/reference/adaptors/examples/sliced.cpp : : example_sliced ]
[ compile ../doc/reference/adaptors/examples/strided.cpp : : example_strided ]
[ compile ../doc/reference/adaptors/examples/tokenized.cpp : : example_tokenized ]
[ compile ../doc/reference/adaptors/examples/transformed.cpp : : example_transformed ]
[ compile ../doc/reference/adaptors/examples/uniqued.cpp : : example_uniqued ]
[ compile-fail compile_fail/iterator_range1.cpp ]
[ range-test adaptor_test/adjacent_filtered ]
[ range-test adaptor_test/copied ]
[ range-test adaptor_test/filtered ]
@@ -155,5 +171,9 @@ test-suite range :
[ range-test std_container ]
[ range-test string ]
[ range-test sub_range ]
[ range-test ticket_5486 ]
[ range-test ticket_5544_terminate_irange ]
[ range-test ticket_5547 ]
[ range-test ticket_5556_is_sorted_namespace ]
;
+33
View File
@@ -250,6 +250,38 @@ namespace boost
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
output.begin(), output.end() );
}
template<typename Range>
void strided_test_ticket_5236_check_bidirectional(const Range& rng)
{
BOOST_CHECK_EQUAL( boost::distance(rng), 1 );
BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), boost::prior(boost::end(rng))), 0 );
}
template<typename Range>
void strided_test_ticket_5236_check(const Range& rng)
{
strided_test_ticket_5236_check_bidirectional(rng);
typename boost::range_iterator<const Range>::type it = boost::end(rng);
it = it - 1;
BOOST_CHECK_EQUAL( std::distance(boost::begin(rng), it), 0 );
}
void strided_test_ticket_5236()
{
std::vector<int> v;
v.push_back(1);
strided_test_ticket_5236_check( v | boost::adaptors::strided(2) );
// Ensure that there is consistency between the random-access implementation
// and the bidirectional.
std::list<int> l;
l.push_back(1);
strided_test_ticket_5236_check_bidirectional( l | boost::adaptors::strided(2) );
}
}
}
@@ -262,6 +294,7 @@ init_unit_test_suite(int argc, char* argv[])
test->add( BOOST_TEST_CASE( &boost::strided_test ) );
test->add( BOOST_TEST_CASE( &boost::strided_defect_Trac5014 ) );
test->add( BOOST_TEST_CASE( &boost::strided_test_traversal ) );
test->add( BOOST_TEST_CASE( &boost::strided_test_ticket_5236 ) );
return test;
}
+21
View File
@@ -0,0 +1,21 @@
// Boost.Range library
//
// Copyright Neil Groves 2011. Use, modification and distribution is subject
// to the Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/range
//
#include <boost/range/iterator_range_core.hpp>
namespace iterator_range_test_detail
{
void check_iterator_range_doesnt_convert_pointers()
{
double source[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
boost::iterator_range<float*> rng = boost::make_iterator_range(source);
}
}
+43 -15
View File
@@ -14,7 +14,6 @@
#include <boost/range/end.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <vector>
namespace boost
@@ -35,27 +34,38 @@ namespace boost
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
reference.begin(), reference.end() );
}
template<typename Integer>
std::ptrdiff_t test_irange_calculate_num_steps(Integer first, Integer last, int step)
{
const std::ptrdiff_t sz = static_cast<std::ptrdiff_t>(step >= 0 ? step : -step);
const std::ptrdiff_t l = static_cast<std::ptrdiff_t>(step >= 0 ? last : first);
const std::ptrdiff_t f = static_cast<std::ptrdiff_t>(step >= 0 ? first : last);
return (l + ((l-f) % sz) - f) / sz;
}
// Test an integer range with a runtime specified step size.
template<typename Integer>
void test_irange_impl(Integer first, Integer last, int step)
template<typename Integer, typename IntegerInput>
void test_irange_impl(IntegerInput first, IntegerInput last, int step)
{
BOOST_ASSERT( step != 0 );
// Skip tests that have negative values if the type is
// unsigned
if ((static_cast<IntegerInput>(static_cast<Integer>(first)) != first)
|| (static_cast<IntegerInput>(static_cast<Integer>(last)) != last))
return;
std::vector<Integer> reference;
if (step > 0)
{
for (Integer i = first; i < last; i += step)
reference.push_back(i);
}
else
{
for (Integer i = first; i > last; i += step)
reference.push_back(i);
}
const std::ptrdiff_t num_steps = test_irange_calculate_num_steps(first, last, step);
Integer current_value = first;
for (std::ptrdiff_t i = 0; i < num_steps; ++i, current_value += step)
reference.push_back(current_value);
std::vector<Integer> test;
boost::push_back(test, boost::irange(first, last, step));
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
reference.begin(), reference.end() );
}
@@ -81,7 +91,6 @@ namespace boost
void test_irange(int first, int last, int step_size)
{
BOOST_ASSERT( step_size != 0 );
BOOST_ASSERT( (last - first) % step_size == 0 );
test_irange_impl<signed char>(first, last, step_size);
test_irange_impl<unsigned char>(first, last, step_size);
test_irange_impl<signed short>(first, last, step_size);
@@ -114,8 +123,27 @@ namespace boost
test_irange(10, 0, -1);
test_irange(0, 2, 2);
test_irange(2, 0, -2);
test_irange(0, 9, 2);
test_irange(9, 0, -2);
test_irange(-9, 0, 2);
test_irange(-9, 9, 2);
test_irange(9, -9, -2);
test_irange(10, 20, 5);
test_irange(20, 10, -5);
test_irange(0, 0, 3);
test_irange(0, 1, 3);
test_irange(0, 2, 3);
test_irange(0, 3, 3);
test_irange(0, 4, 3);
test_irange(0, 10, 3);
test_irange(0, 0, -3);
test_irange(0, -1, -3);
test_irange(0, -2, -3);
test_irange(0, -3, -3);
test_irange(0, -4, -3);
test_irange(0, -10, -3);
}
} // namespace boost
+122 -2
View File
@@ -24,6 +24,7 @@
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <vector>
void check_reference_type();
@@ -102,17 +103,136 @@ void check_iterator_range()
check_reference_type();
}
namespace iterator_range_test_detail
{
struct less
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l < r;
}
};
struct greater
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l > r;
}
};
struct less_or_equal
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l <= r;
}
};
struct greater_or_equal
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l >= r;
}
};
struct equal_to
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l == r;
}
};
struct not_equal_to
{
template< class Left, class Right >
bool operator()(const Left& l, const Right& r) const
{
return l != r;
}
};
template< class Pred >
void check_iterator_range_operators_impl(Pred pred)
{
std::vector<std::string> vals;
vals.push_back(std::string());
vals.push_back("a");
vals.push_back("b");
vals.push_back("z");
vals.push_back("ab");
vals.push_back("ba");
vals.push_back("abc");
vals.push_back("cba");
vals.push_back("aa");
vals.push_back("aaa");
vals.push_back("aab");
vals.push_back("bba");
typedef std::string::const_iterator citer;
typedef boost::iterator_range<citer> iter_range;
typedef std::vector<std::string>::const_iterator value_const_iterator;
value_const_iterator first_val = vals.begin();
value_const_iterator last_val = vals.end();
for (value_const_iterator left_it = first_val; left_it != last_val; ++left_it)
{
const std::string& leftValue = *left_it;
for (value_const_iterator right_it = first_val; right_it != last_val; ++right_it)
{
const std::string& rightValue = *right_it;
iter_range left = boost::make_iterator_range(leftValue);
iter_range right = boost::make_iterator_range(rightValue);
const bool reference = pred(leftValue, rightValue);
BOOST_CHECK_EQUAL( pred(left, right), reference );
BOOST_CHECK_EQUAL( pred(left, rightValue), reference );
BOOST_CHECK_EQUAL( pred(leftValue, right), reference );
}
}
}
void check_iterator_range_from_array()
{
double source[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
boost::iterator_range<double*> rng = boost::make_iterator_range(source);
BOOST_CHECK_EQUAL_COLLECTIONS( rng.begin(), rng.end(),
source, source + 6 );
}
} // namespace iterator_range_test_detail
template<typename Pred>
inline void check_iterator_range_operator()
{
iterator_range_test_detail::check_iterator_range_operators_impl(
Pred());
}
boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
{
boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
test->add( BOOST_TEST_CASE( &check_iterator_range ) );
test->add(BOOST_TEST_CASE(&check_iterator_range));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::less>));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::less_or_equal>));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::greater>));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::greater_or_equal>));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::equal_to>));
test->add(BOOST_TEST_CASE(&check_iterator_range_operator<iterator_range_test_detail::not_equal_to>));
return test;
}
//
//
// Check that constness is propgated correct from
@@ -371,7 +371,7 @@ namespace boost
Container reference(cont);
Container test(cont);
iterator_t range_result = policy.test_iter(test);
iterator_t reference_it = policy.reference(reference);
@@ -391,7 +391,8 @@ namespace boost
Container reference(cont);
Container test_cont(cont);
range_return_t range_result = test_range_t()(policy, test_cont);
test_range_t test_range_fn;
range_return_t range_result = test_range_fn(policy, test_cont);
iterator_t reference_it = policy.reference(reference);
check_results<result_type>::test(test_cont, reference,
+56
View File
@@ -0,0 +1,56 @@
// Boost.Range library
//
// Copyright Neil Groves 2011. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/range/adaptor/adjacent_filtered.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <functional>
#include <vector>
namespace boost
{
namespace
{
class TestTicket5486Pred
: public std::binary_function<int,int,bool>
{
public:
explicit TestTicket5486Pred(int x) {}
bool operator()(int,int) const { return true; }
private:
TestTicket5486Pred();
};
// Ticket 5486 - pertained to predicates erroneous
// requiring default construction
void test_ticket_5486()
{
std::vector<int> v;
boost::push_back(v, v | boost::adaptors::adjacent_filtered(TestTicket5486Pred(1)));
BOOST_CHECK_EQUAL_COLLECTIONS( v.begin(), v.end(),
v.begin(), v.end() );
}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.ticket_5486" );
test->add( BOOST_TEST_CASE( &boost::test_ticket_5486 ) );
return test;
}
+47
View File
@@ -0,0 +1,47 @@
// Boost.Range library
//
// Copyright Neil Groves 2011. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/range/irange.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
namespace boost
{
namespace
{
void test_irange_termination()
{
std::vector<int> reference;
for (int i = 0; i < 9; i += 2)
reference.push_back(i);
std::vector<int> actual;
boost::push_back(actual, boost::irange(0,9,2));
BOOST_CHECK_EQUAL_COLLECTIONS(actual.begin(), actual.end(),
reference.begin(), reference.end());
}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.ticket_5544" );
test->add( BOOST_TEST_CASE( &boost::test_irange_termination ) );
return test;
}
+42
View File
@@ -0,0 +1,42 @@
// Boost.Range library
//
// Copyright Neil Groves 2011. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
#include <boost/algorithm/string/join.hpp>
#include <boost/range/join.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
namespace boost
{
namespace
{
// Ticket 5547 - boost::join ambiguous with algorithm::join
void test_ticket_5547()
{
std::vector<int> x;
boost::range::join(x,x);
}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.ticket_5547" );
test->add( BOOST_TEST_CASE( &boost::test_ticket_5547 ) );
return test;
}
+37
View File
@@ -0,0 +1,37 @@
// Boost.Range library
//
// Copyright Neil Groves 2011. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
// Embarrasingly, the mere inclusion of these headers in this order was
// enough to trigger the defect.
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
namespace boost
{
namespace
{
void test_ticket_5556() {}
}
}
boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.ticket_5556" );
test->add( BOOST_TEST_CASE( &boost::test_ticket_5556 ) );
return test;
}