Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85899 - in trunk: boost/variant boost/variant/detail libs/variant/test
From: antoshkka_at_[hidden]
Date: 2013-09-25 07:54:20


Author: apolukhin
Date: 2013-09-25 07:54:19 EDT (Wed, 25 Sep 2013)
New Revision: 85899
URL: http://svn.boost.org/trac/boost/changeset/85899

Log:
Add experimental variadic templates support to Boost.Variant, enable usage of variadic version for gcc-4.8, clang-3.0 and later compilers (refs #9163)
With this patch size of a binary siginificantly reduced (up to two times)

Text files modified:
   trunk/boost/variant/detail/make_variant_list.hpp | 17 ++++++++++-
   trunk/boost/variant/recursive_variant.hpp | 22 +++++++++++++-
   trunk/boost/variant/variant_fwd.hpp | 60 ++++++++++++++++++++++++++++++++++++++-
   trunk/libs/variant/test/Jamfile.v2 | 7 ++++
   4 files changed, 100 insertions(+), 6 deletions(-)

Modified: trunk/boost/variant/detail/make_variant_list.hpp
==============================================================================
--- trunk/boost/variant/detail/make_variant_list.hpp Wed Sep 25 07:20:43 2013 (r85898)
+++ trunk/boost/variant/detail/make_variant_list.hpp 2013-09-25 07:54:19 EDT (Wed, 25 Sep 2013) (r85899)
@@ -3,8 +3,8 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 //-----------------------------------------------------------------------------
 //
-// Copyright (c) 2002-2003
-// Eric Friedman, Itay Maman
+// Copyright (c) 2002-2003 Eric Friedman, Itay Maman
+// Copyright (c) 2013 Antony Polukhin
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -31,6 +31,17 @@
 // Rationale: see class template convert_void (variant_fwd.hpp) and using-
 // declaration workaround (below).
 //
+
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(BOOST_VARIANT_USE_VARIADIC_TEMPLATES)
+
+template < typename... T >
+struct make_variant_list
+{
+ typedef typename mpl::list< T... >::type type;
+};
+
+#else
+
 template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
 struct make_variant_list
 {
@@ -54,6 +65,8 @@
 
 };
 
+#endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
+
 }} // namespace detail::variant
 } // namespace boost
 

Modified: trunk/boost/variant/recursive_variant.hpp
==============================================================================
--- trunk/boost/variant/recursive_variant.hpp Wed Sep 25 07:20:43 2013 (r85898)
+++ trunk/boost/variant/recursive_variant.hpp 2013-09-25 07:54:19 EDT (Wed, 25 Sep 2013) (r85899)
@@ -3,8 +3,8 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 //-----------------------------------------------------------------------------
 //
-// Copyright (c) 2003
-// Eric Friedman
+// Copyright (c) 2003 Eric Friedman
+// Copyright (c) 2013 Antony Polukhin
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -116,6 +116,23 @@
       BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
>
 {
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(BOOST_VARIANT_USE_VARIADIC_TEMPLATES)
+
+ typedef ::boost::variant<
+ typename enable_recursive<
+ T0
+ , RecursiveVariant
+ , mpl::true_
+ >::type,
+ typename enable_recursive<
+ TN
+ , RecursiveVariant
+ , mpl::true_
+ >::type...
+ > type;
+
+#else
+
 private: // helpers, for metafunction result (below)
 
     #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
@@ -137,6 +154,7 @@
 public: // metafunction result
 
     typedef ::boost::variant< BOOST_VARIANT_ENUM_PARAMS(wknd_T) > type;
+#endif
 };
 
 #else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)

Modified: trunk/boost/variant/variant_fwd.hpp
==============================================================================
--- trunk/boost/variant/variant_fwd.hpp Wed Sep 25 07:20:43 2013 (r85898)
+++ trunk/boost/variant/variant_fwd.hpp 2013-09-25 07:54:19 EDT (Wed, 25 Sep 2013) (r85899)
@@ -3,8 +3,8 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 //-----------------------------------------------------------------------------
 //
-// Copyright (c) 2003
-// Eric Friedman, Itay Maman
+// Copyright (c) 2003 Eric Friedman, Itay Maman
+// Copyright (c) 2013 Antony Polukhin
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -71,6 +71,54 @@
 # define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
 #endif
 
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(BOOST_VARIANT_USE_VARIADIC_TEMPLATES)
+#include <boost/preprocessor/seq/size.hpp>
+
+#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_class class)(
+#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_typename typename)(
+
+#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_class class...
+#define BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_typename typename...
+
+#define ARGS_VARIADER_1(x) x ## N...
+#define ARGS_VARIADER_2(x) BOOST_VARIANT_CLASS_OR_TYPENAME_TO_VARIADIC_ ## x ## N
+
+#define BOOST_VARIANT_MAKE_VARIADIC(sequence, x) BOOST_VARIANT_MAKE_VARIADIC_I(BOOST_PP_SEQ_SIZE(sequence), x)
+#define BOOST_VARIANT_MAKE_VARIADIC_I(argscount, x) BOOST_VARIANT_MAKE_VARIADIC_II(argscount, x)
+#define BOOST_VARIANT_MAKE_VARIADIC_II(argscount, orig) ARGS_VARIADER_ ## argscount(orig)
+
+///////////////////////////////////////////////////////////////////////////////
+// BOOST_VARIANT_ENUM_PARAMS and BOOST_VARIANT_ENUM_SHIFTED_PARAMS
+//
+// Convenience macro for enumeration of variant params.
+// When variadic templates are available expands:
+// BOOST_VARIANT_ENUM_PARAMS(class Something) => class Something0, class... SomethingN
+// BOOST_VARIANT_ENUM_PARAMS(typename Something) => typename Something0, typename... SomethingN
+// BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
+// BOOST_VARIANT_ENUM_PARAMS(Something) => Something0, SomethingN...
+// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(class Something) => class... SomethingN
+// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename Something) => typename... SomethingN
+// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
+// BOOST_VARIANT_ENUM_SHIFTED_PARAMS(Something) => SomethingN...
+//
+// Rationale: Cleaner, simpler code for clients of variant library. Minimal
+// code modifications to move from C++03 to C++11.
+//
+// Without !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(BOOST_VARIANT_USE_VARIADIC_TEMPLATES)
+// will be used BOOST_VARIANT_ENUM_PARAMS and BOOST_VARIANT_ENUM_SHIFTED_PARAMS from below `#else`
+//
+
+#define BOOST_VARIANT_ENUM_PARAMS(x) \
+ x ## 0, \
+ BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \
+ /**/
+
+#define BOOST_VARIANT_ENUM_SHIFTED_PARAMS(x) \
+ BOOST_VARIANT_MAKE_VARIADIC( (BOOST_VARIANT_CLASS_OR_TYPENAME_TO_SEQ_ ## x), x) \
+ /**/
+
+#else
+
 ///////////////////////////////////////////////////////////////////////////////
 // macro BOOST_VARIANT_RECURSIVE_VARIANT_MAX_ARITY
 //
@@ -100,6 +148,7 @@
 #define BOOST_VARIANT_ENUM_SHIFTED_PARAMS( param ) \
     BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_VARIANT_LIMIT_TYPES, param)
 
+#endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
 
 namespace boost {
 
@@ -168,6 +217,11 @@
 
 }} // namespace detail::variant
 
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(BOOST_VARIANT_USE_VARIADIC_TEMPLATES)
+
+#define BOOST_VARIANT_AUX_DECLARE_PARAMS BOOST_VARIANT_ENUM_PARAMS(typename T)
+
+#else
 ///////////////////////////////////////////////////////////////////////////////
 // (detail) macro BOOST_VARIANT_AUX_DECLARE_PARAM
 //
@@ -196,6 +250,8 @@
         ) \
     /**/
 
+#endif // BOOST_NO_CXX11_VARIADIC_TEMPLATES
+
 ///////////////////////////////////////////////////////////////////////////////
 // class template variant (concept inspired by Andrei Alexandrescu)
 //

Modified: trunk/libs/variant/test/Jamfile.v2
==============================================================================
--- trunk/libs/variant/test/Jamfile.v2 Wed Sep 25 07:20:43 2013 (r85898)
+++ trunk/libs/variant/test/Jamfile.v2 2013-09-25 07:54:19 EDT (Wed, 25 Sep 2013) (r85899)
@@ -16,6 +16,13 @@
     : requirements
         #<dependency>/boost/test//minimal
         <toolset>msvc:<asynch-exceptions>on
+ <toolset>gcc-4.8:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>gcc-4.9:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>clang-3.0:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>clang-3.1:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>clang-3.2:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>clang-3.3:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
+ <toolset>clang-3.4:<cxxflags>-DBOOST_VARIANT_USE_VARIADIC_TEMPLATES
     ;
     
 test-suite variant


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