| 1 | #include <boost/container/map.hpp>
|
|---|
| 2 | #include <boost/container/flat_map.hpp>
|
|---|
| 3 | #include <boost/container/vector.hpp>
|
|---|
| 4 | #include <boost/move/move.hpp>
|
|---|
| 5 | #include <iostream>
|
|---|
| 6 |
|
|---|
| 7 | struct Request
|
|---|
| 8 | {
|
|---|
| 9 | Request() {};
|
|---|
| 10 |
|
|---|
| 11 | //Move semantics...
|
|---|
| 12 | Request(BOOST_RV_REF(Request) r) : rvals() //Move constructor
|
|---|
| 13 | {
|
|---|
| 14 | rvals.swap(r.rvals);
|
|---|
| 15 | };
|
|---|
| 16 |
|
|---|
| 17 | Request& operator=(BOOST_RV_REF(Request) r) //Move assignment
|
|---|
| 18 | {
|
|---|
| 19 | if (this != &r){
|
|---|
| 20 | rvals.swap(r.rvals);
|
|---|
| 21 | }
|
|---|
| 22 | return *this;
|
|---|
| 23 | };
|
|---|
| 24 |
|
|---|
| 25 | // Values I want to be moved, not copied.
|
|---|
| 26 | boost::container::vector<int> rvals;
|
|---|
| 27 |
|
|---|
| 28 | private:
|
|---|
| 29 | // Mark this class movable but not copyable
|
|---|
| 30 | BOOST_MOVABLE_BUT_NOT_COPYABLE(Request)
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | typedef boost::container::flat_map<int, Request> Requests;
|
|---|
| 34 | //typedef boost::container::map<int, Request> Requests2;
|
|---|
| 35 |
|
|---|
| 36 | int
|
|---|
| 37 | main() {
|
|---|
| 38 | Requests req;
|
|---|
| 39 | std::pair<Requests::iterator, bool> ret = req.insert( Requests::value_type( 7, Request() ) );
|
|---|
| 40 | std::cout << "Insert success for req: " << ret.second << std::endl;
|
|---|
| 41 |
|
|---|
| 42 | //Requests2 req2;
|
|---|
| 43 | //std::pair<Requests::iterator, bool> ret2 = req2.insert( Requests2::value_type( 7, Request() ) );
|
|---|
| 44 | //std::cout << "Insert success for req2: " << ret2.second << std::endl;
|
|---|
| 45 |
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|