Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76982 - in trunk: boost/utility libs/utility
From: dwalker07_at_[hidden]
Date: 2012-02-11 13:27:03


Author: dlwalker
Date: 2012-02-11 13:27:02 EST (Sat, 11 Feb 2012)
New Revision: 76982
URL: http://svn.boost.org/trac/boost/changeset/76982

Log:
Updated boost::base_from_member for C++2011.
Text files modified:
   trunk/boost/utility/base_from_member.hpp | 12 ++++++++
   trunk/libs/utility/base_from_member.html | 51 +++++++++++++++++++++++++++++----------
   2 files changed, 49 insertions(+), 14 deletions(-)

Modified: trunk/boost/utility/base_from_member.hpp
==============================================================================
--- trunk/boost/utility/base_from_member.hpp (original)
+++ trunk/boost/utility/base_from_member.hpp 2012-02-11 13:27:02 EST (Sat, 11 Feb 2012)
@@ -1,6 +1,6 @@
 // boost utility/base_from_member.hpp header file --------------------------//
 
-// Copyright 2001, 2003, 2004 Daryle Walker. Use, modification, and
+// Copyright 2001, 2003, 2004, 2012 Daryle Walker. Use, modification, and
 // distribution are subject to the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or a copy at
 // <http://www.boost.org/LICENSE_1_0.txt>.)
@@ -10,6 +10,7 @@
 #ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP
 #define BOOST_UTILITY_BASE_FROM_MEMBER_HPP
 
+#include <boost/config.hpp>
 #include <boost/preprocessor/arithmetic/inc.hpp>
 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
 #include <boost/preprocessor/repetition/enum_params.hpp>
@@ -68,12 +69,21 @@
 protected:
     MemberType member;
 
+#if defined(BOOST_HAS_RVALUE_REFS) && defined(BOOST_HAS_VARIADIC_TMPL)
+ template <typename ...T>
+ explicit BOOST_CONSTEXPR base_from_member( T&& ...x )
+ BOOST_NOEXCEPT_IF( BOOST_NOEXCEPT_EXPR(::new ((void*) 0) MemberType(
+ static_cast<T&&>(x)... )) ) // no std::is_nothrow_constructible...
+ : member( static_cast<T&&>(x)... ) // ...nor std::forward needed
+ {}
+#else
     base_from_member()
         : member()
         {}
 
     BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY),
      BOOST_PRIVATE_CTR_DEF, _ )
+#endif
 
 }; // boost::base_from_member
 

Modified: trunk/libs/utility/base_from_member.html
==============================================================================
--- trunk/libs/utility/base_from_member.html (original)
+++ trunk/libs/utility/base_from_member.html 2012-02-11 13:27:02 EST (Sat, 11 Feb 2012)
@@ -129,6 +129,8 @@
 <h2><a name="synopsis">Synopsis</a></h2>
 
 <blockquote><pre>
+#include &lt;type_traits&gt; <i>// exposition only</i>
+
 #ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
 #define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10
 #endif
@@ -139,6 +141,11 @@
 protected:
     MemberType member;
 
+#if <i>C++2011 is in use</i>
+ template&lt; typename ...T &gt;
+ explicit constexpr base_from_member( T&amp;&amp; ...x )
+ noexcept( std::is_nothrow_constructible&lt;MemberType, T...&gt;::value );
+#else
     base_from_member();
 
     template&lt; typename T1 &gt;
@@ -154,6 +161,7 @@
      typename T10 &gt;
     base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
      T8 x8, T9 x9, T10 x10 );
+#endif
 };
 </pre></blockquote>
 
@@ -166,13 +174,27 @@
 data member called <var>member</var> that the derived class can use
 for later base classes (or itself).</p>
 
-<p>There is a default constructor and several constructor member
-templates. These constructor templates can take as many arguments
-(currently up to ten) as possible and pass them to a constructor of
-the data member. Since C++ does not allow any way to explicitly state
+<p>If the variadic template arguments and r-value reference features of C++2011
+are present, there will be a single constructor template. It implements
+&quot;perfect forwarding&quot; to the best constructor call of
+<code>member</code> (if any). The constructor template is marked both
+<code>constexpr</code> and <code>explicit</code>. The former will be ignored
+if the corresponding inner constructor call (of <code>member</code>) does not
+have the marker. The latter binds the other way; always taking effect, even
+when the inner constructor call does not have the marker. The constructor
+template propagates the <code>noexcept</code> status of the inner constructor
+call.</p>
+
+<p>On earlier-standard compilers, there is a default constructor and several
+constructor member templates. These constructor templates can take as many
+arguments (currently up to ten) as possible and pass them to a constructor of
+the data member.</p>
+
+<p>Since C++ does not allow any way to explicitly state
 the template parameters of a templated constructor, make sure that
 the arguments are already close as possible to the actual type used in
-the data member's desired constructor.</p>
+the data member's desired constructor. Explicit conversions may be
+necessary.</p>
 
 <p>The <var>BOOST_BASE_FROM_MEMBER_MAX_ARITY</var> macro constant specifies
 the maximum argument length for the constructor templates. The constant
@@ -180,7 +202,7 @@
 constant may be read for code that is expandable like the class template and
 needs to maintain the same maximum size. (Example code would be a class that
 uses this class template as a base class for a member with a flexible set of
-constructors.)</p>
+constructors.) This constant is ignored when C++2011 features are present.</p>
 
 <h2><a name="usage">Usage</a></h2>
 
@@ -323,11 +345,14 @@
 argument for <code>pbase2_type</code> is converted from <code>int</code>
 to <code>double</code>. The second constructor argument for
 <code>pbase3_type</code> is a special case of necessary conversion; all
-forms of the null-pointer literal in C++ also look like compile-time
-integral expressions, so C++ always interprets such code as an integer
-when it has overloads that can take either an integer or a pointer. The
-last conversion is necessary for the compiler to call a constructor form
-with the exact pointer type used in <code>switcher</code>'s constructor.</p>
+forms of the null-pointer literal in C++ (except <code>nullptr</code> from
+C++2011) also look like compile-time integral expressions, so C++ always
+interprets such code as an integer when it has overloads that can take either
+an integer or a pointer. The last conversion is necessary for the compiler to
+call a constructor form with the exact pointer type used in
+<code>switcher</code>'s constructor. (If C++2011's <code>nullptr</code> is
+used, it still needs a conversion if multiple pointer types can be accepted in
+a constructor call but <code>std::nullptr_t</code> cannot.)</p>
 
 <h2><a name="credits">Credits</a></h2>
 
@@ -360,9 +385,9 @@
 
 <hr>
 
-<p>Revised: 28 August 2004</p>
+<p>Revised: 11 February 2012</p>
 
-<p>Copyright 2001, 2003, 2004 Daryle Walker. Use, modification, and distribution
+<p>Copyright 2001, 2003, 2004, 2012 Daryle Walker. Use, modification, and distribution
 are subject to the Boost Software License, Version 1.0. (See accompanying
 file LICENSE_1_0.txt or a copy at &lt;<a
 href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt>&gt;.)</p>


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