[SVN r84546]
This commit is contained in:
Ion Gaztañaga
2013-05-29 10:07:00 +00:00
parent dbc1ef7722
commit ebab4240b2
2 changed files with 23 additions and 11 deletions

View File

@ -129,9 +129,12 @@ Consider a simple handle class that owns a resource and also provides copy seman
clone_ptr& operator=(clone_ptr&& p) clone_ptr& operator=(clone_ptr&& p)
{ {
std::swap(ptr, p.ptr); if(this != &p)
delete p.ptr; {
p.ptr = 0; std::swap(ptr, p.ptr);
delete p.ptr;
p.ptr = 0;
}
return *this; return *this;
} }
@ -171,7 +174,7 @@ You just need to follow these simple steps:
* Put the following macro in the [*private] section: * Put the following macro in the [*private] section:
[macroref BOOST_COPYABLE_AND_MOVABLE BOOST_COPYABLE_AND_MOVABLE(classname)] [macroref BOOST_COPYABLE_AND_MOVABLE BOOST_COPYABLE_AND_MOVABLE(classname)]
* Left copy constructor as is. * Leave copy constructor as is.
* Write a copy assignment taking the parameter as * Write a copy assignment taking the parameter as
[macroref BOOST_COPY_ASSIGN_REF BOOST_COPY_ASSIGN_REF(classname)] [macroref BOOST_COPY_ASSIGN_REF BOOST_COPY_ASSIGN_REF(classname)]
* Write a move constructor and a move assignment taking the parameter as * Write a move constructor and a move assignment taking the parameter as
@ -787,10 +790,18 @@ Many thanks to all boosters that have tested, reviewed and improved the library.
[section:release_notes Release Notes] [section:release_notes Release Notes]
[section:release_notes_boost_1_55_00 Boost 1.55 Release]
* Fixed bug [@https://svn.boost.org/trac/boost/ticket/7952 #7952]).
[endsect]
[section:release_notes_boost_1_54_00 Boost 1.54 Release] [section:release_notes_boost_1_54_00 Boost 1.54 Release]
* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7969 #7969]), * Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7969 #7969]),
[@https://svn.boost.org/trac/boost/ticket/8231 #8231]). [@https://svn.boost.org/trac/boost/ticket/8231 #8231]).
[endsect] [endsect]

View File

@ -10,6 +10,7 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#include <cassert>
//[file_descriptor_def //[file_descriptor_def
@ -24,8 +25,8 @@ class file_descriptor
return 1; return 1;
} }
void operating_system_close_file(int) void operating_system_close_file(int fd)
{} { (void)fd; assert(fd != 0); }
//-> //->
int os_descr_; int os_descr_;
@ -33,12 +34,12 @@ class file_descriptor
BOOST_MOVABLE_BUT_NOT_COPYABLE(file_descriptor) BOOST_MOVABLE_BUT_NOT_COPYABLE(file_descriptor)
public: public:
explicit file_descriptor(const char *filename = 0) //Constructor explicit file_descriptor(const char *filename) //Constructor
: os_descr_(filename ? operating_system_open_file(filename) : 0) : os_descr_(operating_system_open_file(filename))
{ if(!os_descr_) throw std::runtime_error("file not found"); } { if(!os_descr_) throw std::runtime_error("file not found"); }
~file_descriptor() //Destructor ~file_descriptor() //Destructor
{ if(!os_descr_) operating_system_close_file(os_descr_); } { if(os_descr_) operating_system_close_file(os_descr_); }
file_descriptor(BOOST_RV_REF(file_descriptor) x) // Move ctor file_descriptor(BOOST_RV_REF(file_descriptor) x) // Move ctor
: os_descr_(x.os_descr_) : os_descr_(x.os_descr_)
@ -46,7 +47,7 @@ class file_descriptor
file_descriptor& operator=(BOOST_RV_REF(file_descriptor) x) // Move assign file_descriptor& operator=(BOOST_RV_REF(file_descriptor) x) // Move assign
{ {
if(!os_descr_) operating_system_close_file(os_descr_); if(os_descr_) operating_system_close_file(os_descr_);
os_descr_ = x.os_descr_; os_descr_ = x.os_descr_;
x.os_descr_ = 0; x.os_descr_ = 0;
return *this; return *this;