Hotfix to add back advance_begin and advance_end.

This commit is contained in:
Neil Groves
2014-08-04 17:53:14 +01:00
parent 4716c1efec
commit 7fb879a283
5 changed files with 77 additions and 0 deletions

View File

@ -73,6 +73,10 @@ namespace boost
void drop_front();
void drop_front(difference_type n);
bool empty() const;
iterator_range& advance_begin(difference_type n);
iterator_range& advance_end(difference_type n);
// for Bidirectional:
value_type& back() const;
void drop_back();
@ -263,6 +267,9 @@ namespace boost
reference front();
const_reference front() const;
sub_range& advance_begin(difference_type n);
sub_range& advance_end(difference_type n);
// If traversal >= bidirectional:
reference back();
const_reference back();

View File

@ -267,6 +267,9 @@ public:
std::advance(this->m_Begin, n);
}
// Deprecated
void pop_front() { drop_front(); }
protected:
template<class Iterator>
void assign(Iterator first, Iterator last)
@ -331,6 +334,9 @@ public:
BOOST_ASSERT(n >= difference_type());
std::advance(this->m_End, -n);
}
// Deprecated
void pop_back() { drop_back(); }
};
template<class IteratorT>
@ -528,6 +534,20 @@ public:
return *this;
}
iterator_range& advance_begin(
BOOST_DEDUCED_TYPENAME base_type::difference_type n)
{
std::advance(this->m_Begin, n);
return *this;
}
iterator_range& advance_end(
BOOST_DEDUCED_TYPENAME base_type::difference_type n)
{
std::advance(this->m_End, n);
return *this;
}
protected:
//
// Allow subclasses an easy way to access the

View File

@ -261,6 +261,20 @@ public:
iterator_range_::operator=( static_cast<const iterator_range_&>(r) );
return *this;
}
sub_range& advance_begin(
BOOST_DEDUCED_TYPENAME base::difference_type n)
{
std::advance(this->m_Begin, n);
return *this;
}
sub_range& advance_end(
BOOST_DEDUCED_TYPENAME base::difference_type n)
{
std::advance(this->m_End, n);
return *this;
}
};
} // namespace 'boost'

View File

@ -249,6 +249,23 @@ inline void check_iterator_range_operator()
Pred());
}
inline void test_advance()
{
std::vector<int> l;
l.push_back(1);
l.push_back(2);
typedef boost::iterator_range<std::vector<int>::iterator> rng_t;
rng_t r1(l.begin(), l.end());
BOOST_CHECK(r1.advance_begin(1).advance_end(-1).empty());
rng_t r2(l.begin(), l.end());
BOOST_CHECK_EQUAL(r2.advance_begin(1).size(), 1u);
rng_t r3(l.begin(), l.end());
BOOST_CHECK_EQUAL(r3.advance_end(-1).size(), 1u);
}
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" );
@ -261,6 +278,7 @@ boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
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>));
test->add(BOOST_TEST_CASE(&iterator_range_test_detail::check_make_iterator_range_n));
test->add(BOOST_TEST_CASE(&test_advance));
return test;
}

View File

@ -228,6 +228,22 @@ void const_propagation_const_collection(void)
check_constant_type(crng.back());
}
inline void test_advance()
{
std::vector<int> l;
l.push_back(1);
l.push_back(2);
typedef boost::sub_range<std::vector<int> > rng_t;
rng_t r1(l.begin(), l.end());
BOOST_CHECK(r1.advance_begin(1).advance_end(-1).empty());
rng_t r2(l.begin(), l.end());
BOOST_CHECK_EQUAL(r2.advance_begin(1).size(), 1u);
rng_t r3(l.begin(), l.end());
BOOST_CHECK_EQUAL(r3.advance_end(-1).size(), 1u);
}
} // anonymous namespace
} // namespace boost_range_test
@ -244,6 +260,8 @@ boost::unit_test::test_suite* init_unit_test_suite(int, char*[])
test->add(BOOST_TEST_CASE(
&boost_range_test::const_propagation_mutable_collection));
test->add(BOOST_TEST_CASE(&boost_range_test::test_advance));
return test;
}