/*============================================================================= 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 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 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::value && !is_same::value) , make_indices_from_seq >::type > dispatch( Sequence const& ) 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> >::type* = 0) : 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()); } typedef extension::value_at_impl value_at_impl; template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED typename value_at_impl::template apply::type& at_impl(J) { typedef typename value_at_impl::template apply::type U; typedef store S; return static_cast(this)->get(); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED typename value_at_impl::template apply::type const& at_impl(J) const { typedef typename value_at_impl::template apply::type U; typedef store S; return static_cast(this)->get(); } }; // Internal use only specialization for implementing vectorN. // Simple aliasing (like a using vectorN = vector) will cause specialization confliction // like following. // // template struct SomeClass; // template struct SomeClass> { ... }; // template // struct SomeClass> // Error, since vector and vector1 are exact same type. // { ... }; // // Introducing `numbered_vector_tag` will resolve such specialization error. // // template // struct SomeClass> { ... }; // template // struct SomeClass> // OK // { ... }; // // // Same meaning as above specialization. // template // struct SomeClass, T>> // { ... }; template struct construct_vector_; template struct construct_vector_ > { typedef vector_data< typename detail::make_index_sequence::type , T... > type; }; template struct construct_vector_, T...> > { typedef vector_data< typename detail::make_index_sequence::type , T... > type; BOOST_STATIC_ASSERT((type::size::value == N)); }; template struct construct_vector_, void_, Tail...> : construct_vector_ > {}; template struct construct_vector_, Head, Tail...> : construct_vector_, Tail...> {}; template struct construct_vector : construct_vector_, T...> {}; } // namespace boost::fusion::vector_detail // This class provides backward compatibility: vector. template struct vector : vector_detail::construct_vector::type { typedef typename vector_detail::construct_vector::type 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(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