|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r82008 - in sandbox-branches/geometry/index: boost/geometry/extensions/index test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-15 21:40:29
Author: awulkiew
Date: 2012-12-15 21:40:29 EST (Sat, 15 Dec 2012)
New Revision: 82008
URL: http://svn.boost.org/trac/boost/changeset/82008
Log:
Added static_vector::insert(pos, n, val) + test.
Text files modified:
sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp | 37 +++++++++++++++++++++++++++++++++++++
sandbox-branches/geometry/index/test/static_vector.cpp | 15 +++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)
Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-15 21:40:29 EST (Sat, 15 Dec 2012)
@@ -187,6 +187,43 @@
}
// basic
+ void insert(iterator position, size_type count, value_type const& value)
+ {
+ // TODO change name of this macro
+ BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM(difference_type dist = std::distance(this->begin(), position));
+ BOOST_ASSERT_MSG(0 <= dist && (sizeof(dist)<=sizeof(m_size)?((size_type)dist<=m_size):(dist<=(difference_type)m_size)), "invalid iterator");
+
+ BOOST_ASSERT_MSG(m_size + count <= Capacity, "size can't exceed the capacity");
+ //if ( Capacity < m_size + count ) throw std::bad_alloc();
+
+ if ( position == this->end() )
+ {
+ std::uninitialized_fill(position, position + count, value); // may throw
+ m_size += count; // update end
+ }
+ else
+ {
+ difference_type to_move = std::distance(position, this->end());
+
+ if ( count < static_cast<size_type>(to_move) )
+ {
+ this->uninitialized_copy(this->end() - count, this->end(), this->end()); // may throw
+ m_size += count; // update end
+ this->move_backward(position, position + to_move - count, this->end() - count); // may throw
+ std::fill_n(position, count, value); // may throw
+ }
+ else
+ {
+ std::uninitialized_fill(this->end(), position + count, value); // may throw
+ m_size += count - to_move; // update end
+ this->uninitialized_copy(position, position + to_move, position + count); // may throw
+ m_size += to_move; // update end
+ std::fill_n(position, to_move, value); // may throw
+ }
+ }
+ }
+
+ // basic
void erase(iterator position)
{
// TODO change name of this macro
Modified: sandbox-branches/geometry/index/test/static_vector.cpp
==============================================================================
--- sandbox-branches/geometry/index/test/static_vector.cpp (original)
+++ sandbox-branches/geometry/index/test/static_vector.cpp 2012-12-15 21:40:29 EST (Sat, 15 Dec 2012)
@@ -373,6 +373,21 @@
for ( size_t i = 0 ; i < h ; ++i )
BOOST_CHECK(s1[i+h] == v);
}
+
+ {
+ size_t n = size_t(h/1.5f);
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ static_vector<T, N> s1(s);
+ s1.insert(s1.begin() + i, n, v);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == v);
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
+ }
+ }
}
int test_main(int, char* [])
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk