]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/example/doc_move_containers.cpp
1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2009-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 //[doc_move_containers
12 #include <boost/container/vector.hpp>
13 #include <boost/move/utility_core.hpp>
19 BOOST_MOVABLE_BUT_NOT_COPYABLE(non_copyable
)
23 non_copyable(BOOST_RV_REF(non_copyable
)) {}
24 non_copyable
& operator=(BOOST_RV_REF(non_copyable
)) { return *this; }
29 using namespace boost::container
;
31 //Store non-copyable objects in a vector
32 vector
<non_copyable
> v
;
34 v
.push_back(boost::move(nc
));
35 assert(v
.size() == 1);
37 //Reserve no longer needs copy-constructible
39 assert(v
.capacity() >= 100);
41 //This resize overload only needs movable and default constructible
43 assert(v
.size() == 200);
45 //Containers are also movable
46 vector
<non_copyable
> v_other(boost::move(v
));
47 assert(v_other
.size() == 200);