From 275f65f9ad60eb6e1f3e0f3212c423689d0476b6 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 9 Nov 2014 15:26:28 +0900 Subject: [PATCH 1/7] Implement C++11 Variadic Templates based list. --- .../fusion/container/generation/make_list.hpp | 30 ++++++ .../container/list/detail/list_to_cons.hpp | 55 +++++++++++ include/boost/fusion/container/list/list.hpp | 91 +++++++++++++++++++ .../boost/fusion/container/list/list_fwd.hpp | 25 +++++ 4 files changed, 201 insertions(+) diff --git a/include/boost/fusion/container/generation/make_list.hpp b/include/boost/fusion/container/generation/make_list.hpp index 0aafb272..fbe93979 100644 --- a/include/boost/fusion/container/generation/make_list.hpp +++ b/include/boost/fusion/container/generation/make_list.hpp @@ -10,7 +10,37 @@ #include #include +#if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 variadic interface +/////////////////////////////////////////////////////////////////////////////// + +#include + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct make_list + { + typedef list type; + }; + } + + template + BOOST_FUSION_GPU_ENABLED + inline list::type...> + make_list(T const&... arg) + { + return list::type...>(arg...); + } + }} + #endif +#endif diff --git a/include/boost/fusion/container/list/detail/list_to_cons.hpp b/include/boost/fusion/container/list/detail/list_to_cons.hpp index e967c892..780d637e 100644 --- a/include/boost/fusion/container/list/detail/list_to_cons.hpp +++ b/include/boost/fusion/container/list/detail/list_to_cons.hpp @@ -13,6 +13,61 @@ /////////////////////////////////////////////////////////////////////////////// // Without variadics, we will use the PP version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +#include + +namespace boost { namespace fusion { namespace detail +{ + template + struct list_to_cons; + + template <> + struct list_to_cons<> + { + typedef nil_ type; + }; + + template + struct list_to_cons + { + typedef Head head_type; + typedef list_to_cons<> tail_list_to_cons; + typedef typename tail_list_to_cons::type tail_type; + + typedef cons type; + + BOOST_FUSION_GPU_ENABLED + static type + call(typename detail::call_param::type _h) + { + return type(_h); + } + }; + + template + struct list_to_cons + { + typedef Head head_type; + typedef list_to_cons tail_list_to_cons; + typedef typename tail_list_to_cons::type tail_type; + + typedef cons type; + + BOOST_FUSION_GPU_ENABLED + static type + call(typename detail::call_param::type _h, + typename detail::call_param::type ..._t) + { + return type(_h, tail_list_to_cons::call(_t...)); + } + }; +}}} #endif +#endif diff --git a/include/boost/fusion/container/list/list.hpp b/include/boost/fusion/container/list/list.hpp index b07f0fc9..ebf8b03d 100644 --- a/include/boost/fusion/container/list/list.hpp +++ b/include/boost/fusion/container/list/list.hpp @@ -13,6 +13,97 @@ /////////////////////////////////////////////////////////////////////////////// // Without variadics, we will use the PP version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +#include + +namespace boost { namespace fusion +{ + struct nil_; + struct void_; + + template <> + struct list<> + : detail::list_to_cons<>::type + { + private: + typedef detail::list_to_cons<> list_to_cons; + + public: + typedef list_to_cons::type inherited_type; + + BOOST_FUSION_GPU_ENABLED + list() + : inherited_type() {} + + template + BOOST_FUSION_GPU_ENABLED + list(Sequence const& rhs) + : inherited_type(rhs) {} + + template + BOOST_FUSION_GPU_ENABLED + list& + operator=(Sequence const& rhs) + { + inherited_type::operator=(rhs); + return *this; + } + }; + + template + struct list + : detail::list_to_cons::type + { + private: + typedef detail::list_to_cons list_to_cons; + + public: + typedef typename list_to_cons::type inherited_type; + + BOOST_FUSION_GPU_ENABLED + list() + : inherited_type() {} + + template + BOOST_FUSION_GPU_ENABLED + list(list const& rhs) + : inherited_type(rhs) {} + + template + BOOST_FUSION_GPU_ENABLED + list(Sequence const& rhs) + : inherited_type(rhs) {} + + BOOST_FUSION_GPU_ENABLED + explicit + list(typename detail::call_param::type ...args) + : inherited_type(list_to_cons::call(args...)) {} + + template + BOOST_FUSION_GPU_ENABLED + list& + operator=(list const& rhs) + { + inherited_type::operator=(rhs); + return *this; + } + + template + BOOST_FUSION_GPU_ENABLED + list& + operator=(Sequence const& rhs) + { + inherited_type::operator=(rhs); + return *this; + } + }; +}} #endif +#endif diff --git a/include/boost/fusion/container/list/list_fwd.hpp b/include/boost/fusion/container/list/list_fwd.hpp index d7ea0dcd..c5f26192 100644 --- a/include/boost/fusion/container/list/list_fwd.hpp +++ b/include/boost/fusion/container/list/list_fwd.hpp @@ -10,9 +10,34 @@ #include #include +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \ + || (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)) +# if defined(BOOST_FUSION_HAS_VARIADIC_LIST) +# undef BOOST_FUSION_HAS_VARIADIC_LIST +# endif +#else +# if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) +# define BOOST_FUSION_HAS_VARIADIC_LIST +# endif +#endif + /////////////////////////////////////////////////////////////////////////////// // With no variadics, we will use the C++03 version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace fusion +{ + struct void_; + + template + struct list; +}} #endif +#endif From 3d0412bfd161c61c5c0c30ea4b11c962552fe2f1 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 31 May 2015 20:34:50 +0900 Subject: [PATCH 2/7] constexpr support for variadic list. --- .../fusion/container/generation/make_list.hpp | 2 +- include/boost/fusion/container/list/list.hpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/boost/fusion/container/generation/make_list.hpp b/include/boost/fusion/container/generation/make_list.hpp index fbe93979..13eba30d 100644 --- a/include/boost/fusion/container/generation/make_list.hpp +++ b/include/boost/fusion/container/generation/make_list.hpp @@ -32,7 +32,7 @@ namespace boost { namespace fusion } template - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline list::type...> make_list(T const&... arg) { diff --git a/include/boost/fusion/container/list/list.hpp b/include/boost/fusion/container/list/list.hpp index ebf8b03d..2ceea7be 100644 --- a/include/boost/fusion/container/list/list.hpp +++ b/include/boost/fusion/container/list/list.hpp @@ -37,7 +37,7 @@ namespace boost { namespace fusion public: typedef list_to_cons::type inherited_type; - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} @@ -47,7 +47,7 @@ namespace boost { namespace fusion : inherited_type(rhs) {} template - BOOST_FUSION_GPU_ENABLED + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED list& operator=(Sequence const& rhs) { @@ -66,12 +66,12 @@ namespace boost { namespace fusion public: typedef typename list_to_cons::type inherited_type; - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} template - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list(list const& rhs) : inherited_type(rhs) {} @@ -80,13 +80,13 @@ namespace boost { namespace fusion list(Sequence const& rhs) : inherited_type(rhs) {} - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit list(typename detail::call_param::type ...args) : inherited_type(list_to_cons::call(args...)) {} template - BOOST_FUSION_GPU_ENABLED + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED list& operator=(list const& rhs) { @@ -95,7 +95,7 @@ namespace boost { namespace fusion } template - BOOST_FUSION_GPU_ENABLED + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED list& operator=(Sequence const& rhs) { From d1973805409a841c6fd109a5d6f887263044fb50 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 18 Jun 2015 08:31:07 +0900 Subject: [PATCH 3/7] Implement C++11 list_tie. --- .../generation/detail/pp_list_tie.hpp | 2 +- .../fusion/container/generation/list_tie.hpp | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/boost/fusion/container/generation/detail/pp_list_tie.hpp b/include/boost/fusion/container/generation/detail/pp_list_tie.hpp index 561677f9..be25627a 100644 --- a/include/boost/fusion/container/generation/detail/pp_list_tie.hpp +++ b/include/boost/fusion/container/generation/detail/pp_list_tie.hpp @@ -53,7 +53,7 @@ namespace boost { namespace fusion // $$$ shouldn't we remove_reference first to allow references? $$$ #define BOOST_FUSION_REF(z, n, data) BOOST_PP_CAT(T, n)& -#define BOOST_PP_FILENAME_1 +#define BOOST_PP_FILENAME_1 #define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_LIST_SIZE) #include BOOST_PP_ITERATE() diff --git a/include/boost/fusion/container/generation/list_tie.hpp b/include/boost/fusion/container/generation/list_tie.hpp index afc0ab2f..91907167 100644 --- a/include/boost/fusion/container/generation/list_tie.hpp +++ b/include/boost/fusion/container/generation/list_tie.hpp @@ -10,7 +10,35 @@ #include #include +#if !defined(BOOST_FUSION_HAS_VARIADIC_LIST) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 variadic interface +/////////////////////////////////////////////////////////////////////////////// + +namespace boost { namespace fusion +{ + namespace result_of + { + template + struct list_tie + { + typedef list type; + }; + } + + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline list + list_tie(T&... arg) + { + return list(arg...); + } +}} + +#endif #endif From 0e8e857c2f97a50410ee48cd8ba4e1e30a104ffb Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Mon, 22 Jun 2015 23:43:49 +0900 Subject: [PATCH 4/7] Fix fusion::make_list return type. --- include/boost/fusion/container/generation/make_list.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/fusion/container/generation/make_list.hpp b/include/boost/fusion/container/generation/make_list.hpp index 13eba30d..e88f553a 100644 --- a/include/boost/fusion/container/generation/make_list.hpp +++ b/include/boost/fusion/container/generation/make_list.hpp @@ -27,16 +27,16 @@ namespace boost { namespace fusion template struct make_list { - typedef list type; + typedef list::type...> type; }; } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - inline list::type...> + inline typename result_of::make_list::type make_list(T const&... arg) { - return list::type...>(arg...); + return typename result_of::make_list::type(arg...); } }} From 78c5228d93dd1c95323b5bbd3de5c29458cd4759 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Tue, 23 Jun 2015 00:37:24 +0900 Subject: [PATCH 5/7] Move internal type into private. --- include/boost/fusion/container/list/detail/cpp03/list.hpp | 3 +-- .../container/list/detail/cpp03/preprocessed/list10.hpp | 2 +- .../container/list/detail/cpp03/preprocessed/list20.hpp | 2 +- .../container/list/detail/cpp03/preprocessed/list30.hpp | 2 +- .../container/list/detail/cpp03/preprocessed/list40.hpp | 2 +- .../container/list/detail/cpp03/preprocessed/list50.hpp | 2 +- include/boost/fusion/container/list/list.hpp | 8 +++----- 7 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/boost/fusion/container/list/detail/cpp03/list.hpp b/include/boost/fusion/container/list/detail/cpp03/list.hpp index 41b3caff..b39489b0 100644 --- a/include/boost/fusion/container/list/detail/cpp03/list.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/list.hpp @@ -46,10 +46,9 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list10.hpp b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list10.hpp index 9a289365..69ffc9c2 100644 --- a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list10.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list10.hpp @@ -18,8 +18,8 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list20.hpp b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list20.hpp index a201cb44..0d6ea768 100644 --- a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list20.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list20.hpp @@ -18,8 +18,8 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list30.hpp b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list30.hpp index ef9e65fc..9087c119 100644 --- a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list30.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list30.hpp @@ -18,8 +18,8 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list40.hpp b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list40.hpp index 570b2ccd..24a474fe 100644 --- a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list40.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list40.hpp @@ -18,8 +18,8 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list50.hpp b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list50.hpp index d237cdf9..b810bea1 100644 --- a/include/boost/fusion/container/list/detail/cpp03/preprocessed/list50.hpp +++ b/include/boost/fusion/container/list/detail/cpp03/preprocessed/list50.hpp @@ -18,8 +18,8 @@ namespace boost { namespace fusion typedef detail::list_to_cons list_to_cons; - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} diff --git a/include/boost/fusion/container/list/list.hpp b/include/boost/fusion/container/list/list.hpp index 2ceea7be..d291baf9 100644 --- a/include/boost/fusion/container/list/list.hpp +++ b/include/boost/fusion/container/list/list.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (c) 2014 Kohei Takahashi + Copyright (c) 2014-2015 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -33,10 +33,9 @@ namespace boost { namespace fusion { private: typedef detail::list_to_cons<> list_to_cons; - - public: typedef list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} @@ -62,10 +61,9 @@ namespace boost { namespace fusion { private: typedef detail::list_to_cons list_to_cons; - - public: typedef typename list_to_cons::type inherited_type; + public: BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED list() : inherited_type() {} From 5cceded23b8dd02b8728fde57916fe2f81ed6c21 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Tue, 23 Jun 2015 08:56:58 +0900 Subject: [PATCH 6/7] Drop unnecessary specialization. --- .../container/list/detail/list_to_cons.hpp | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/include/boost/fusion/container/list/detail/list_to_cons.hpp b/include/boost/fusion/container/list/detail/list_to_cons.hpp index 780d637e..1ce1cfba 100644 --- a/include/boost/fusion/container/list/detail/list_to_cons.hpp +++ b/include/boost/fusion/container/list/detail/list_to_cons.hpp @@ -1,5 +1,5 @@ /*============================================================================= - Copyright (c) 2014 Kohei Takahashi + Copyright (c) 2014-2015 Kohei Takahashi Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,6 +7,7 @@ #ifndef FUSION_LIST_MAIN_10262014_0447 #define FUSION_LIST_MAIN_10262014_0447 +#include #include #include @@ -21,6 +22,7 @@ // C++11 interface /////////////////////////////////////////////////////////////////////////////// #include +#include namespace boost { namespace fusion { namespace detail { @@ -31,23 +33,9 @@ namespace boost { namespace fusion { namespace detail struct list_to_cons<> { typedef nil_ type; - }; - template - struct list_to_cons - { - typedef Head head_type; - typedef list_to_cons<> tail_list_to_cons; - typedef typename tail_list_to_cons::type tail_type; - - typedef cons type; - - BOOST_FUSION_GPU_ENABLED - static type - call(typename detail::call_param::type _h) - { - return type(_h); - } + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + static type call() { return type(); } }; template @@ -59,7 +47,7 @@ namespace boost { namespace fusion { namespace detail typedef cons type; - BOOST_FUSION_GPU_ENABLED + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED static type call(typename detail::call_param::type _h, typename detail::call_param::type ..._t) From d5ce74dffd0d461a931dc90cb36b5919ba80f99b Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 24 Jun 2015 15:26:33 +0900 Subject: [PATCH 7/7] Added move ctor/assign for c++11 fusion::list. --- include/boost/fusion/container/list/list.hpp | 50 ++++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/include/boost/fusion/container/list/list.hpp b/include/boost/fusion/container/list/list.hpp index d291baf9..865a6d7d 100644 --- a/include/boost/fusion/container/list/list.hpp +++ b/include/boost/fusion/container/list/list.hpp @@ -20,12 +20,12 @@ /////////////////////////////////////////////////////////////////////////////// // C++11 interface /////////////////////////////////////////////////////////////////////////////// +#include #include namespace boost { namespace fusion { struct nil_; - struct void_; template <> struct list<> @@ -40,6 +40,7 @@ namespace boost { namespace fusion list() : inherited_type() {} +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template BOOST_FUSION_GPU_ENABLED list(Sequence const& rhs) @@ -53,6 +54,21 @@ namespace boost { namespace fusion inherited_type::operator=(rhs); return *this; } +#else + template + BOOST_FUSION_GPU_ENABLED + list(Sequence&& rhs) + : inherited_type(std::forward(rhs)) {} + + template + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + list& + operator=(Sequence&& rhs) + { + inherited_type::operator=(std::forward(rhs)); + return *this; + } +#endif }; template @@ -68,30 +84,24 @@ namespace boost { namespace fusion list() : inherited_type() {} - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - list(list const& rhs) - : inherited_type(rhs) {} - +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template BOOST_FUSION_GPU_ENABLED list(Sequence const& rhs) : inherited_type(rhs) {} +#else + template + BOOST_FUSION_GPU_ENABLED + list(Sequence&& rhs) + : inherited_type(std::forward(rhs)) {} +#endif BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit list(typename detail::call_param::type ...args) : inherited_type(list_to_cons::call(args...)) {} - template - BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED - list& - operator=(list const& rhs) - { - inherited_type::operator=(rhs); - return *this; - } - +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED list& @@ -100,6 +110,16 @@ namespace boost { namespace fusion inherited_type::operator=(rhs); return *this; } +#else + template + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + list& + operator=(Sequence&& rhs) + { + inherited_type::operator=(std::forward(rhs)); + return *this; + } +#endif }; }}