From b4133761e8dcd81e461f0b4c2e5d8029100d7b62 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sat, 29 Nov 2014 23:04:29 +0900 Subject: [PATCH] Implement C++11 variadic templates based fusion::set --- .../fusion/container/set/detail/as_set.hpp | 50 +++++++- .../container/set/detail/convert_impl.hpp | 2 +- include/boost/fusion/container/set/set.hpp | 111 ++++++++++++++++++ .../boost/fusion/container/set/set_fwd.hpp | 27 +++++ 4 files changed, 188 insertions(+), 2 deletions(-) diff --git a/include/boost/fusion/container/set/detail/as_set.hpp b/include/boost/fusion/container/set/detail/as_set.hpp index 1eb0d3fe..9d333258 100644 --- a/include/boost/fusion/container/set/detail/as_set.hpp +++ b/include/boost/fusion/container/set/detail/as_set.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) @@ -13,7 +13,55 @@ /////////////////////////////////////////////////////////////////////////////// // Without variadics, we will use the PP version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_SET) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion { namespace detail +{ +BOOST_FUSION_BARRIER_BEGIN + + template ::type> + struct as_set; + + template + struct as_set > + { + template + struct apply + { + typedef set< + typename result_of::value_of< + typename result_of::advance_c::type + >::type... + > type; + }; + + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + static typename apply::type + call(Iterator const& i) + { + typedef apply gen; + typedef typename gen::type result; + return result(*advance_c(i)...); + } + }; + +BOOST_FUSION_BARRIER_END +}}} #endif +#endif diff --git a/include/boost/fusion/container/set/detail/convert_impl.hpp b/include/boost/fusion/container/set/detail/convert_impl.hpp index d9d5dcfc..0b4cb22f 100644 --- a/include/boost/fusion/container/set/detail/convert_impl.hpp +++ b/include/boost/fusion/container/set/detail/convert_impl.hpp @@ -29,7 +29,7 @@ namespace boost { namespace fusion template struct apply { - typedef typename detail::as_set::value> gen; + typedef detail::as_set::value> gen; typedef typename gen:: template apply::type>::type type; diff --git a/include/boost/fusion/container/set/set.hpp b/include/boost/fusion/container/set/set.hpp index 59f4eafc..9e383619 100644 --- a/include/boost/fusion/container/set/set.hpp +++ b/include/boost/fusion/container/set/set.hpp @@ -13,8 +13,119 @@ /////////////////////////////////////////////////////////////////////////////// // Without variadics, we will use the PP version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_SET) # include +#else +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct fusion_sequence_tag; + + template <> + struct set<> : sequence_base > + { + struct category : forward_traversal_tag, associative_tag {}; + + typedef set_tag fusion_tag; + typedef fusion_sequence_tag tag; // this gets picked up by MPL + typedef mpl::false_ is_view; + + typedef vector<> storage_type; + + typedef storage_type::size size; + + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + set() + : data() {} + + template + BOOST_FUSION_GPU_ENABLED + set(Sequence const& rhs) + : data(rhs) {} + + template + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + set& + operator=(T const& rhs) + { + data = rhs; + return *this; + } + + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + storage_type& get_data() { return data; } + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + storage_type const& get_data() const { return data; } + + private: + storage_type data; + }; + + template + struct set : sequence_base > + { + struct category : forward_traversal_tag, associative_tag {}; + + typedef set_tag fusion_tag; + typedef fusion_sequence_tag tag; // this gets picked up by MPL + typedef mpl::false_ is_view; + + typedef vector storage_type; + + typedef typename storage_type::size size; + + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + set() + : data() {} + + template + BOOST_FUSION_GPU_ENABLED + set(Sequence const& rhs) + : data(rhs) {} + + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + explicit + set(typename detail::call_param::type ...args) + : data(args...) {} + + template + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + set& + operator=(U const& rhs) + { + data = rhs; + return *this; + } + + BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED + storage_type& get_data() { return data; } + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + storage_type const& get_data() const { return data; } + + private: + storage_type data; + }; + +}} + +#endif #endif diff --git a/include/boost/fusion/container/set/set_fwd.hpp b/include/boost/fusion/container/set/set_fwd.hpp index 50d8d1c8..7b5d6830 100644 --- a/include/boost/fusion/container/set/set_fwd.hpp +++ b/include/boost/fusion/container/set/set_fwd.hpp @@ -9,11 +9,38 @@ #include #include +#include + +#if !defined(BOOST_FUSION_HAS_VARIADIC_VECTOR) \ + || (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)) +# if defined(BOOST_FUSION_HAS_VARIADIC_SET) +# undef BOOST_FUSION_HAS_VARIADIC_SET +# endif +#else +# if !defined(BOOST_FUSION_HAS_VARIADIC_SET) +# define BOOST_FUSION_HAS_VARIADIC_SET +# endif +#endif /////////////////////////////////////////////////////////////////////////////// // With no variadics, we will use the C++03 version /////////////////////////////////////////////////////////////////////////////// +#if !defined(BOOST_FUSION_HAS_VARIADIC_SET) # include +#else + +/////////////////////////////////////////////////////////////////////////////// +// C++11 interface +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace fusion +{ + struct set_tag; + struct set_iterator_tag; + + template + struct set; +}} #endif +#endif