mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 23:14:02 +00:00
Updated boost::base_from_member for C++2011.
[SVN r76982]
This commit is contained in:
parent
fe653d0a9a
commit
e763315b55
@ -129,6 +129,8 @@ particular member type does not need to concern itself with the integer.</p>
|
|||||||
<h2><a name="synopsis">Synopsis</a></h2>
|
<h2><a name="synopsis">Synopsis</a></h2>
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
|
#include <type_traits> <i>// exposition only</i>
|
||||||
|
|
||||||
#ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
|
#ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
|
||||||
#define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10
|
#define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10
|
||||||
#endif
|
#endif
|
||||||
@ -139,6 +141,11 @@ class boost::base_from_member
|
|||||||
protected:
|
protected:
|
||||||
MemberType member;
|
MemberType member;
|
||||||
|
|
||||||
|
#if <i>C++2011 is in use</i>
|
||||||
|
template< typename ...T >
|
||||||
|
explicit constexpr base_from_member( T&& ...x )
|
||||||
|
noexcept( std::is_nothrow_constructible<MemberType, T...>::value );
|
||||||
|
#else
|
||||||
base_from_member();
|
base_from_member();
|
||||||
|
|
||||||
template< typename T1 >
|
template< typename T1 >
|
||||||
@ -154,6 +161,7 @@ protected:
|
|||||||
typename T10 >
|
typename T10 >
|
||||||
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
|
||||||
T8 x8, T9 x9, T10 x10 );
|
T8 x8, T9 x9, T10 x10 );
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
@ -166,13 +174,27 @@ value of zero if it is omitted. The class template has a protected
|
|||||||
data member called <var>member</var> that the derived class can use
|
data member called <var>member</var> that the derived class can use
|
||||||
for later base classes (or itself).</p>
|
for later base classes (or itself).</p>
|
||||||
|
|
||||||
<p>There is a default constructor and several constructor member
|
<p>If the variadic template arguments and r-value reference features of C++2011
|
||||||
templates. These constructor templates can take as many arguments
|
are present, there will be a single constructor template. It implements
|
||||||
(currently up to ten) as possible and pass them to a constructor of
|
"perfect forwarding" to the best constructor call of
|
||||||
the data member. Since C++ does not allow any way to explicitly state
|
<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 template parameters of a templated constructor, make sure that
|
||||||
the arguments are already close as possible to the actual type used in
|
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
|
<p>The <var>BOOST_BASE_FROM_MEMBER_MAX_ARITY</var> macro constant specifies
|
||||||
the maximum argument length for the constructor templates. The constant
|
the maximum argument length for the constructor templates. The constant
|
||||||
@ -180,7 +202,7 @@ may be overridden if more (or less) argument configurations are needed. The
|
|||||||
constant may be read for code that is expandable like the class template and
|
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
|
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
|
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>
|
<h2><a name="usage">Usage</a></h2>
|
||||||
|
|
||||||
@ -323,11 +345,14 @@ constructor argument for <code>pbase0_type</code> is converted from
|
|||||||
argument for <code>pbase2_type</code> is converted from <code>int</code>
|
argument for <code>pbase2_type</code> is converted from <code>int</code>
|
||||||
to <code>double</code>. The second constructor argument for
|
to <code>double</code>. The second constructor argument for
|
||||||
<code>pbase3_type</code> is a special case of necessary conversion; all
|
<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
|
forms of the null-pointer literal in C++ (except <code>nullptr</code> from
|
||||||
integral expressions, so C++ always interprets such code as an integer
|
C++2011) also look like compile-time integral expressions, so C++ always
|
||||||
when it has overloads that can take either an integer or a pointer. The
|
interprets such code as an integer when it has overloads that can take either
|
||||||
last conversion is necessary for the compiler to call a constructor form
|
an integer or a pointer. The last conversion is necessary for the compiler to
|
||||||
with the exact pointer type used in <code>switcher</code>'s constructor.</p>
|
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>
|
<h2><a name="credits">Credits</a></h2>
|
||||||
|
|
||||||
@ -360,9 +385,9 @@ with the exact pointer type used in <code>switcher</code>'s constructor.</p>
|
|||||||
|
|
||||||
<hr>
|
<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
|
are subject to the Boost Software License, Version 1.0. (See accompanying
|
||||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||||
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// boost utility/base_from_member.hpp header file --------------------------//
|
// 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
|
// distribution are subject to the Boost Software License, Version 1.0. (See
|
||||||
// accompanying file LICENSE_1_0.txt or a copy at
|
// accompanying file LICENSE_1_0.txt or a copy at
|
||||||
// <http://www.boost.org/LICENSE_1_0.txt>.)
|
// <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||||
@ -10,6 +10,7 @@
|
|||||||
#ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP
|
#ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP
|
||||||
#define 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/arithmetic/inc.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
@ -68,12 +69,21 @@ class base_from_member
|
|||||||
protected:
|
protected:
|
||||||
MemberType member;
|
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()
|
base_from_member()
|
||||||
: member()
|
: member()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY),
|
BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY),
|
||||||
BOOST_PRIVATE_CTR_DEF, _ )
|
BOOST_PRIVATE_CTR_DEF, _ )
|
||||||
|
#endif
|
||||||
|
|
||||||
}; // boost::base_from_member
|
}; // boost::base_from_member
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user