|
Boost : |
Subject: [boost] [utility] Don't mind if I "change" base_from_member?
From: Daryle Walker (darylew_at_[hidden])
Date: 2012-02-08 01:11:57
Since the suggested trick of using GCC (4.6) from MacPorts as a Darwin GCC worked, I've tried out my first C++11 update: base_from member. It's very straightforward.
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$Index: boost/utility/base_from_member.hpp===================================================================--- boost/utility/base_from_member.hpp (revision 76917)+++ boost/utility/base_from_member.hpp (working copy)@@ -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,19 @@ 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 )+ : member( static_cast<T&&>(x)... ) // some libs don't have std::forward+ {}+#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 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
I don't use std::forward because I've heard that some beta C++11 modes implement the core-language ideas needed (r-value references) but not the library changes (i.e. std::move and std::forward), and I didn't want to find (and conditionally?) #include another header. What I got will work just fine, right? Do the constructors need any marking besides "explicit" and "constexpr"? (I believe the "constexpr" will be safely ignored if the forwarded constructor isn't "constexpr" itself without a compile-time error. It was designed that way, right?) I'll just update the documentation and commit the change, then.
Daryle W.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk