/*============================================================================= 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) ==============================================================================*/ #ifndef FUSION_VECTOR_11052014_1625 #define FUSION_VECTOR_11052014_1625 #include #include #include #include /////////////////////////////////////////////////////////////////////////////// // Without variadics, we will use the PP version /////////////////////////////////////////////////////////////////////////////// #if !defined(BOOST_FUSION_HAS_VARIADIC_VECTOR) # include #else /////////////////////////////////////////////////////////////////////////////// // C++11 interface /////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace fusion { struct vector_tag; struct random_access_traversal_tag; namespace vector_detail { struct each_elem {}; struct copy_or_move {}; template struct from_sequence {}; template struct make_indices_from_seq : detail::make_index_sequence< fusion::result_of::size::type>::value > {}; template struct pure : remove_cv::type> {}; template ::value> struct is_convertible_to_first : boost::is_convertible::type> {}; template struct is_convertible_to_first : mpl::false_ {}; template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline each_elem dispatch(T const&...) BOOST_NOEXCEPT { return each_elem(); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline copy_or_move dispatch(This const&) BOOST_NOEXCEPT { return copy_or_move(); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline from_sequence< typename lazy_enable_if_c< (traits::is_sequence::type>::value && !is_same::type>::value && !is_convertible_to_first::value) , make_indices_from_seq >::type > dispatch(Sequence&&) BOOST_NOEXCEPT { return from_sequence::type>(); } // forward_at_c allows to access Nth element even if ForwardSequence // since fusion::at_c requires RandomAccessSequence. namespace result_of { template struct forward_at_c : fusion::result_of::deref< typename fusion::result_of::advance_c< typename fusion::result_of::begin< typename remove_reference::type >::type , N >::type > {}; } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::forward_at_c::type forward_at_c(Sequence&& seq) { typedef typename result_of::forward_at_c::type result; return std::forward(*advance_c(begin(seq))); } // Object proxy since preserve object order template struct store { BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store() : elem() // value-initialized explicitly {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store(store const& rhs) : elem(rhs.get()) {} BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED store& operator=(store const& rhs) { elem = rhs.get(); return *this; } BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store(store&& rhs) : elem(static_cast(rhs.get())) {} BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED store& operator=(store&& rhs) { elem = static_cast(rhs.get()); return *this; } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store(U&& rhs , typename disable_if::type, store>, detail::enabler_>::type = detail::enabler) : elem(std::forward(rhs)) {} template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED typename disable_if::type, store>, store&>::type operator=(U&& rhs) { elem = std::forward(rhs); return *this; } BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED T & get() { return elem; } BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED T const& get() const { return elem; } T elem; }; template struct vector_data; template struct vector_data, T...> : store... , sequence_base, T...> > { typedef vector_tag fusion_tag; typedef fusion_sequence_tag tag; // this gets picked up by MPL typedef mpl::false_ is_view; typedef random_access_traversal_tag category; typedef mpl::int_ size; typedef vector type_sequence; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector_data() {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector_data(copy_or_move, vector_data const& rhs) : store(static_cast const&>(rhs))... {} BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector_data(copy_or_move, vector_data&& rhs) : store(std::forward >(rhs))... {} template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit vector_data(from_sequence >, Sequence&& rhs) : store(forward_at_c(rhs))... {} template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED explicit vector_data(each_elem, U&&... var) : store(std::forward(var))... {} template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED void assign(Sequence&&, detail::index_sequence<>) {} template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED void assign(Sequence&& seq, detail::index_sequence) { at_impl(mpl::int_()) = vector_detail::forward_at_c(seq); assign(std::forward(seq), detail::index_sequence()); } template static BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED auto at_detail(store* this_) -> decltype(this_->get()) { return this_->get(); } template static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED auto at_detail(store const* this_) -> decltype(this_->get()) { return this_->get(); } template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED auto at_impl(J) -> decltype(at_detail(this)) { return at_detail(this); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED auto at_impl(J) const -> decltype(at_detail(this)) { return at_detail(this); } template static BOOST_FUSION_GPU_ENABLED mpl::identity value_at_impl(store*); }; } // namespace boost::fusion::vector_detail // This class provides backward compatibility: vector. template struct vector : vector_detail::vector_data< typename detail::make_index_sequence::type , T... > { typedef vector_detail::vector_data< typename detail::make_index_sequence::type , T... > base; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector() {} // rvalue-references is required here in order to forward any arguments to // base: vector(T const&...) doesn't work with trailing void_ and // vector(U const&...) cannot forward any arguments to base. template // XXX: constexpr become error due to pull-request #79, booooo!! // In the (near) future release, should be fixed. /* BOOST_CONSTEXPR */ BOOST_FUSION_GPU_ENABLED vector(U&&... u) : base(vector_detail::dispatch(std::forward(u)...), std::forward(u)...) {} template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector& operator=(Sequence&& rhs) { typedef typename vector_detail::make_indices_from_seq::type indices; base::assign(std::forward(rhs), indices()); return *this; } }; }} #endif #endif