From 50bb3d9fdf7f7341d25569b5a7c6c6ebea134867 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sun, 16 Dec 2012 00:58:07 +0000 Subject: [PATCH] Error fixed in static_vector::insert(pos, val). Test added. [SVN r82002] --- .../extensions/index/static_vector.hpp | 2 +- test/static_vector.cpp | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/boost/geometry/extensions/index/static_vector.hpp b/include/boost/geometry/extensions/index/static_vector.hpp index 5226dccaf..5f36514a2 100644 --- a/include/boost/geometry/extensions/index/static_vector.hpp +++ b/include/boost/geometry/extensions/index/static_vector.hpp @@ -181,7 +181,7 @@ public: { this->uninitialized_fill(this->end(), *(this->end() - 1)); // may throw ++m_size; // update end - this->move_backward(position + 1, this->end() - 2, this->end() - 1); // may throw + this->move_backward(position, this->end() - 2, this->end() - 1); // may throw this->fill(position, value); // may throw } } diff --git a/test/static_vector.cpp b/test/static_vector.cpp index f8107f5c9..c2bdf7d87 100644 --- a/test/static_vector.cpp +++ b/test/static_vector.cpp @@ -343,6 +343,28 @@ void test_erase_nd() } } +template +void test_insert_nd(T const& v) +{ + size_t h = N/2; + + static_vector s; + + for ( size_t i = 0 ; i < h ; ++i ) + s.push_back(T(i)); + + { + static_vector s1(s); + for ( size_t i = 0 ; i < h ; ++i ) + s1.insert(s1.begin(), v); + BOOST_CHECK(s1.size() == 2*h); + for ( size_t i = 0 ; i < h ; ++i ) + BOOST_CHECK(s1[i] == v); + for ( size_t i = 0 ; i < h ; ++i ) + BOOST_CHECK(s1[i+h] == T(i)); + } +} + int test_main(int, char* []) { BOOST_CHECK(counting_value::count() == 0); @@ -397,5 +419,10 @@ int test_main(int, char* []) test_erase_nd(); BOOST_CHECK(counting_value::count() == 0); + test_insert_nd(50); + test_insert_nd(value_nd(50)); + test_insert_nd(counting_value(50)); + BOOST_CHECK(counting_value::count() == 0); + return 0; }