Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83869 - in branches/release: boost libs/utility
From: vicente.botet_at_[hidden]
Date: 2013-04-13 09:49:53


Author: viboes
Date: 2013-04-13 09:49:52 EDT (Sat, 13 Apr 2013)
New Revision: 83869
URL: http://svn.boost.org/trac/boost/changeset/83869

Log:
utility/noncopyable : fix #6578.
Text files modified:
   branches/release/boost/noncopyable.hpp | 18 +++++++++++++++---
   branches/release/libs/utility/utility.htm | 10 +++++++---
   2 files changed, 22 insertions(+), 6 deletions(-)

Modified: branches/release/boost/noncopyable.hpp
==============================================================================
--- branches/release/boost/noncopyable.hpp (original)
+++ branches/release/boost/noncopyable.hpp 2013-04-13 09:49:52 EDT (Sat, 13 Apr 2013)
@@ -9,6 +9,8 @@
 #ifndef BOOST_NONCOPYABLE_HPP_INCLUDED
 #define BOOST_NONCOPYABLE_HPP_INCLUDED
 
+#include <boost/config.hpp>
+
 namespace boost {
 
 // Private copy constructor and copy assignment ensure classes derived from
@@ -21,11 +23,21 @@
   class noncopyable
   {
    protected:
- noncopyable() {}
+#ifndef BOOST_NO_DEFAULTED_FUNCTIONS
+ BOOST_CONSTEXPR noncopyable() = default;
+ ~noncopyable() = default;
+#else
+ noncopyable() {}
       ~noncopyable() {}
- private: // emphasize the following members are private
+#endif
+#ifndef BOOST_NO_DELETED_FUNCTIONS
+ noncopyable( const noncopyable& ) = delete;
+ noncopyable& operator=( const noncopyable& ) = delete;
+#else
+ private: // emphasize the following members are private
       noncopyable( const noncopyable& );
- const noncopyable& operator=( const noncopyable& );
+ noncopyable& operator=( const noncopyable& );
+#endif
   };
 }
 

Modified: branches/release/libs/utility/utility.htm
==============================================================================
--- branches/release/libs/utility/utility.htm (original)
+++ branches/release/libs/utility/utility.htm 2013-04-13 09:49:52 EDT (Sat, 13 Apr 2013)
@@ -84,8 +84,10 @@
                         will prevent the otherwise implicitly-generated functions (which don't have the
                         proper semantics) from becoming a trap for other programmers.</p>
                 <p>The traditional way to deal with these is to declare a private copy constructor
- and copy assignment, and then document why this is done.&nbsp; But deriving
- from <b>noncopyable</b> is simpler and clearer, and doesn't require additional
+ and copy assignment, and then document why this is done.&nbsp; A new alternative
+ was introduced in C++2011, declaring a copy constructor and a copy assignment
+ operator, but marking both as <code>delete</code>d.&nbsp; Deriving
+ from <b>noncopyable</b> is simpler and clearer, and doesn't require additional
                         documentation.</p>
                 <p>The program noncopyable_test.cpp can be used
                         to verify class <b>noncopyable</b> works as expected. It has have been run
@@ -106,7 +108,9 @@
                         about the effect on compiler optimization of adding (even trivial inline)
                         destructor declarations. He says &quot;Probably this concern is misplaced,
                         because noncopyable will be used mostly for classes which own resources and
- thus have non-trivial destruction semantics.&quot;</p>
+ thus have non-trivial destruction semantics.&quot;&nbsp; With C++2011, using an
+ optimized and trivial constructor and similar destructor can be enforced by
+ declaring both and marking them <code>default</code>.</p>
                 <h2><a name="addressof">Function template addressof()</a></h2>
                 <p>Function <strong>addressof()</strong> returns the address of an object.</p>
                 <blockquote>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk