Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/boost/container/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,13 @@ class small_vector
inline void swap(small_vector &other)
{ return this->base_type::prot_swap(other, static_capacity); }

//! <b>Effects</b>: x.swap(y)
//!
//! <b>Complexity</b>: Linear to the number of elements stored in the small buffers.
inline friend void swap(small_vector &x, small_vector &y)
BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
{ x.swap(y); }

//! <b>Effects</b>: Tries to reduce capacity() to the current size(). Once the capacity
//! changes, the container permanently switches to dynamically allocated storage even if
//! the resulting size would fit in the internal buffer.
Expand Down
19 changes: 19 additions & 0 deletions test/small_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ bool test_small_vector_base_test()
//small vector has internal storage so some special swap cases must be tested
bool test_swap()
{
{ //Unqualified swap must use small_vector's capacity-aware swap through ADL
typedef boost::container::small_vector<int, 2> small_vec;
small_vec v;
v.push_back(1);
v.push_back(11);

small_vec w;
w.push_back(2);
w.push_back(22);

small_vec v_copy = v;
small_vec w_copy = w;

swap(v, w);

if (w != v_copy || v != w_copy || !v.is_small() || !w.is_small())
return false;
}

typedef boost::container::small_vector<int, 10> vec;
{ //v bigger than static capacity, w empty
vec v;
Expand Down