mirror of
https://github.com/boostorg/move.git
synced 2025-07-31 12:57:14 +02:00
Updated documentation and tests to Boost.Container
[SVN r74156]
This commit is contained in:
@ -18,12 +18,11 @@
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
[important To be able to use containers of movable-only values you will need to use containers supporting move sematantics,
|
[important To be able to use containers of movable-only values you will need to use containers
|
||||||
like [*Boost.Interprocess] containers]
|
supporting move semantics, like [*Boost.Container] containers]
|
||||||
|
|
||||||
[note Tested compilers: MSVC-7.1, 8.0, 9.0, GCC 4.3-MinGW in C++03 and C++0x modes, Intel 10.1]
|
[note Tested compilers: MSVC-7.1, 8.0, 9.0, GCC 4.3-MinGW in C++03 and C++0x modes, Intel 10.1]
|
||||||
|
|
||||||
|
|
||||||
[section:what_is_boost_move What is Boost.Move?]
|
[section:what_is_boost_move What is Boost.Move?]
|
||||||
|
|
||||||
Rvalue references are a major C++0x feature, enabling move semantics for C++ values. However, we
|
Rvalue references are a major C++0x feature, enabling move semantics for C++ values. However, we
|
||||||
@ -285,7 +284,7 @@ movable and copyable types are more efficiently handled if those containers
|
|||||||
internally use move semantics instead of copy semantics.
|
internally use move semantics instead of copy semantics.
|
||||||
If the container needs to "change the location" of an element
|
If the container needs to "change the location" of an element
|
||||||
internally (e.g. vector reallocation) it will move the element instead of copying it.
|
internally (e.g. vector reallocation) it will move the element instead of copying it.
|
||||||
[*Boost.Interprocess] containers are move-aware so you can write the following:
|
[*Boost.Container] containers are move-aware so you can write the following:
|
||||||
|
|
||||||
[file_descriptor_example]
|
[file_descriptor_example]
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class file_descriptor
|
|||||||
//]
|
//]
|
||||||
|
|
||||||
//[file_descriptor_example
|
//[file_descriptor_example
|
||||||
#include <boost/interprocess/containers/vector.hpp>
|
#include <boost/container/vector.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
//Remember: 'file_descriptor' is NOT copyable, but it
|
//Remember: 'file_descriptor' is NOT copyable, but it
|
||||||
@ -72,7 +72,7 @@ int main()
|
|||||||
assert(!fd.empty());
|
assert(!fd.empty());
|
||||||
|
|
||||||
//Now move fd into a vector
|
//Now move fd into a vector
|
||||||
boost::interprocess::vector<file_descriptor> v;
|
boost::container::vector<file_descriptor> v;
|
||||||
v.push_back(boost::move(fd));
|
v.push_back(boost::move(fd));
|
||||||
|
|
||||||
//Check ownership has been transferred
|
//Check ownership has been transferred
|
||||||
@ -81,7 +81,7 @@ int main()
|
|||||||
|
|
||||||
//Compilation error if uncommented since file_descriptor is not copyable
|
//Compilation error if uncommented since file_descriptor is not copyable
|
||||||
//and vector copy construction requires value_type's copy constructor:
|
//and vector copy construction requires value_type's copy constructor:
|
||||||
//boost::interprocess::vector<file_descriptor> v2(v);
|
//boost::container::vector<file_descriptor> v2(v);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//[move_inserter_example
|
//[move_inserter_example
|
||||||
#include <boost/interprocess/containers/list.hpp>
|
#include <boost/container/list.hpp>
|
||||||
#include "movable.hpp"
|
#include "movable.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
using namespace ::boost::interprocess;
|
using namespace ::boost::container;
|
||||||
|
|
||||||
typedef list<movable> list_t;
|
typedef list<movable> list_t;
|
||||||
typedef list_t::iterator l_iterator;
|
typedef list_t::iterator l_iterator;
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//[move_iterator_example
|
//[move_iterator_example
|
||||||
#include <boost/interprocess/containers/vector.hpp>
|
#include <boost/container/vector.hpp>
|
||||||
#include "movable.hpp"
|
#include "movable.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace ::boost::interprocess;
|
using namespace ::boost::container;
|
||||||
|
|
||||||
//Create a vector with 10 default constructed objects
|
//Create a vector with 10 default constructed objects
|
||||||
vector<movable> v(10);
|
vector<movable> v(10);
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
#include <boost/move/move.hpp>
|
#include <boost/move/move.hpp>
|
||||||
#include <boost/interprocess/containers/vector.hpp>
|
#include <boost/container/deque.hpp>
|
||||||
#include <boost/interprocess/containers/list.hpp>
|
#include <boost/container/list.hpp>
|
||||||
#include <boost/interprocess/containers/stable_vector.hpp>
|
#include <boost/container/stable_vector.hpp>
|
||||||
#include "../example/movable.hpp"
|
#include "../example/movable.hpp"
|
||||||
|
|
||||||
template<class Container>
|
template<class Container>
|
||||||
@ -46,15 +46,15 @@ int move_test()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
namespace bi = ::boost::interprocess;
|
namespace bc = ::boost::container;
|
||||||
|
|
||||||
if(move_test< bi::vector<movable> >()){
|
if(move_test< bc::vector<movable> >()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(move_test< bi::list<movable> >()){
|
if(move_test< bc::list<movable> >()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(move_test< bi::stable_vector<movable> >()){
|
if(move_test< bc::stable_vector<movable> >()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -9,15 +9,15 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
#include <boost/move/move.hpp>
|
#include <boost/move/move.hpp>
|
||||||
#include <boost/interprocess/containers/vector.hpp>
|
#include <boost/container/vector.hpp>
|
||||||
#include "../example/movable.hpp"
|
#include "../example/movable.hpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
namespace bi = ::boost::interprocess;
|
namespace bc = ::boost::container;
|
||||||
//Default construct 10 movable objects
|
//Default construct 10 movable objects
|
||||||
bi::vector<movable> v(10);
|
bc::vector<movable> v(10);
|
||||||
bi::vector<movable> v2(10);
|
bc::vector<movable> v2(10);
|
||||||
|
|
||||||
//Move to v2
|
//Move to v2
|
||||||
boost::move(v.begin(), v.end(), v2.begin());
|
boost::move(v.begin(), v.end(), v2.begin());
|
||||||
|
@ -10,14 +10,14 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <boost/move/move.hpp>
|
#include <boost/move/move.hpp>
|
||||||
#include <boost/interprocess/containers/vector.hpp>
|
#include <boost/container/vector.hpp>
|
||||||
#include "../example/movable.hpp"
|
#include "../example/movable.hpp"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
namespace bi = ::boost::interprocess;
|
namespace bc = ::boost::container;
|
||||||
//Default construct 10 movable objects
|
//Default construct 10 movable objects
|
||||||
bi::vector<movable> v(10);
|
bc::vector<movable> v(10);
|
||||||
|
|
||||||
//Test default constructed value
|
//Test default constructed value
|
||||||
if(v[0].moved()){
|
if(v[0].moved()){
|
||||||
@ -25,7 +25,7 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Move values
|
//Move values
|
||||||
bi::vector<movable> v2
|
bc::vector<movable> v2
|
||||||
(boost::make_move_iterator(v.begin()), boost::make_move_iterator(v.end()));
|
(boost::make_move_iterator(v.begin()), boost::make_move_iterator(v.end()));
|
||||||
|
|
||||||
//Test values have been moved
|
//Test values have been moved
|
||||||
|
Reference in New Issue
Block a user