[boost][range] - Improved the implementation of strided range to eliminate requirements for boost::size(rng) to be a valid expression. Each traversal category of strided_iterator is now individually implemented.

[SVN r67461]
This commit is contained in:
Neil Groves
2010-12-26 20:33:33 +00:00
parent fd63de33e9
commit efb7b50a8a
101 changed files with 725 additions and 669 deletions
+3 -13
View File
@@ -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;
};
+4 -3
View File
@@ -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()
+10 -42
View File
@@ -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;
}