Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84798 - in trunk: boost/config boost/config/compiler libs/config/doc
From: andrey.semashev_at_[hidden]
Date: 2013-06-15 13:34:04


Author: andysem
Date: 2013-06-15 13:34:04 EDT (Sat, 15 Jun 2013)
New Revision: 84798
URL: http://svn.boost.org/trac/boost/changeset/84798

Log:
Added BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS, BOOST_DEFAULTED_FUNCTION and BOOST_DELETED_FUNCTION macros for portable declaration of defaulted and deleted functions.

Text files modified:
   trunk/boost/config/compiler/gcc.hpp | 5 +++
   trunk/boost/config/suffix.hpp | 30 +++++++++++++++++++++
   trunk/libs/config/doc/macro_reference.qbk | 55 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 90 insertions(+), 0 deletions(-)

Modified: trunk/boost/config/compiler/gcc.hpp
==============================================================================
--- trunk/boost/config/compiler/gcc.hpp Sat Jun 15 12:58:25 2013 (r84797)
+++ trunk/boost/config/compiler/gcc.hpp 2013-06-15 13:34:04 EDT (Sat, 15 Jun 2013) (r84798)
@@ -217,6 +217,11 @@
 # define BOOST_NO_SFINAE_EXPR
 #endif
 
+// GCC 4.5 forbids declaration of defaulted functions in private or protected sections
+#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 5)
+# define BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS
+#endif
+
 // C++0x features in 4.5.0 and later
 //
 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5) || !defined(__GXX_EXPERIMENTAL_CXX0X__)

Modified: trunk/boost/config/suffix.hpp
==============================================================================
--- trunk/boost/config/suffix.hpp Sat Jun 15 12:58:25 2013 (r84797)
+++ trunk/boost/config/suffix.hpp 2013-06-15 13:34:04 EDT (Sat, 15 Jun 2013) (r84798)
@@ -689,6 +689,36 @@
 # define BOOST_ALIGNMENT(x)
 #endif
 
+// Defaulted and deleted function declaration helpers
+// These macros are intended to be inside a class definition.
+// BOOST_DEFAULTED_FUNCTION accepts the function declaration and its
+// body, which will be used if the compiler doesn't support defaulted functions.
+// BOOST_DELETED_FUNCTION only accepts the function declaration. It
+// will expand to a private function declaration, if the compiler doesn't support
+// deleted functions. Because of this it is recommended to use BOOST_DELETED_FUNCTION
+// in the end of the class definition.
+//
+// class my_class
+// {
+// public:
+// // Default-constructible
+// BOOST_DEFAULTED_FUNCTION(my_class(), {})
+// // Copying prohibited
+// BOOST_DELETED_FUNCTION(my_class(my_class const&))
+// BOOST_DELETED_FUNCTION(my_class& operator= (my_class const&))
+// };
+//
+#if !(defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS))
+# define BOOST_DEFAULTED_FUNCTION(fun, body) fun = default;
+#else
+# define BOOST_DEFAULTED_FUNCTION(fun, body) fun body
+#endif
+
+#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
+# define BOOST_DELETED_FUNCTION(fun) fun = delete;
+#else
+# define BOOST_DELETED_FUNCTION(fun) private: fun;
+#endif
 
 //
 // Set BOOST_NO_DECLTYPE_N3276 when BOOST_NO_DECLTYPE is defined

Modified: trunk/libs/config/doc/macro_reference.qbk
==============================================================================
--- trunk/libs/config/doc/macro_reference.qbk Sat Jun 15 12:58:25 2013 (r84797)
+++ trunk/libs/config/doc/macro_reference.qbk 2013-06-15 13:34:04 EDT (Sat, 15 Jun 2013) (r84798)
@@ -751,6 +751,61 @@
   BOOST_STATIC_CONSTEXPR UIntType xor_mask = a;
 ``
 ]]
+[[`BOOST_DEFAULTED_FUNCTION(fun, body)`][
+This macro is intended to be used within a class definition in order to declare a default implementation of function `fun`.
+For the compilers that do not support C++11 defaulted functions the macro will expand into an inline function definition
+with the `body` implementation. For example:
+``
+ struct my_struct
+ {
+ BOOST_DEFAULTED_FUNCTION(my_struct(), {})
+ };
+``
+is equivalent to:
+``
+ struct my_struct
+ {
+ my_struct() = default;
+ };
+``
+or:
+``
+ struct my_struct
+ {
+ my_struct() {}
+ };
+``
+]]
+[[`BOOST_DELETED_FUNCTION(fun)`][
+This macro is intended to be used within a class definition in order to declare a deleted function `fun`.
+For the compilers that do not support C++11 deleted functions the macro will expand into a private function
+declaration with no definition. Since the macro may change the access mode, it is recommended to use this macro
+at the end of the class definition. For example:
+``
+ struct noncopyable
+ {
+ BOOST_DELETED_FUNCTION(noncopyable(noncopyable const&))
+ BOOST_DELETED_FUNCTION(noncopyable& operator= (noncopyable const&))
+ };
+``
+is equivalent to:
+``
+ struct noncopyable
+ {
+ noncopyable(noncopyable const&) = delete;
+ noncopyable& operator= (noncopyable const&) = delete;
+ };
+``
+or:
+``
+ struct noncopyable
+ {
+ private:
+ noncopyable(noncopyable const&);
+ noncopyable& operator= (noncopyable const&);
+ };
+``
+]]
 [[
 ``
   BOOST_NOEXCEPT


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