From 1ad2e59e072d726abe3dad78fe130af19c1445b8 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Tue, 20 Oct 2015 20:12:14 +0900 Subject: [PATCH] Make fusion::at,N> O(1). --- .../fusion/container/vector/detail/config.hpp | 3 +- .../container/vector/detail/value_at_impl.hpp | 24 ++++---------- .../boost/fusion/container/vector/vector.hpp | 32 ++++++++++++------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/boost/fusion/container/vector/detail/config.hpp b/include/boost/fusion/container/vector/detail/config.hpp index 475fe641..84f4605d 100644 --- a/include/boost/fusion/container/vector/detail/config.hpp +++ b/include/boost/fusion/container/vector/detail/config.hpp @@ -13,7 +13,8 @@ #if (defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \ || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) \ - || defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)) \ + || defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) \ + || defined(BOOST_NO_CXX11_DECLTYPE)) \ || (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES)) # if defined(BOOST_FUSION_HAS_VARIADIC_VECTOR) # undef BOOST_FUSION_HAS_VARIADIC_VECTOR diff --git a/include/boost/fusion/container/vector/detail/value_at_impl.hpp b/include/boost/fusion/container/vector/detail/value_at_impl.hpp index 220807c7..3d748afd 100644 --- a/include/boost/fusion/container/vector/detail/value_at_impl.hpp +++ b/include/boost/fusion/container/vector/detail/value_at_impl.hpp @@ -21,8 +21,9 @@ /////////////////////////////////////////////////////////////////////////////// // C++11 interface /////////////////////////////////////////////////////////////////////////////// -#include #include +#include +#include namespace boost { namespace fusion { @@ -42,23 +43,12 @@ namespace boost { namespace fusion template <> struct value_at_impl { - template - struct apply_impl; - - template - struct apply_impl, 0> - { - typedef H type; - }; - - template - struct apply_impl, N> - : apply_impl, N - 1> - {}; - template - struct apply : apply_impl - {}; + struct apply + { + typedef typename boost::remove_cv::type seq; + typedef decltype(seq::template value_at_impl(boost::declval())) type; + }; }; } }} diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index 9c5032f9..4ca4b237 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -230,27 +230,37 @@ namespace boost { namespace fusion assign(std::forward(seq), detail::index_sequence()); } - typedef extension::value_at_impl value_at_impl; + 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 - typename value_at_impl::template apply::type& - at_impl(J) + auto at_impl(J) -> decltype(at_detail(this)) { - typedef typename value_at_impl::template apply::type U; - typedef store S; - return static_cast(this)->get(); + return at_detail(this); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - typename value_at_impl::template apply::type const& - at_impl(J) const + auto at_impl(J) const -> decltype(at_detail(this)) { - typedef typename value_at_impl::template apply::type U; - typedef store S; - return static_cast(this)->get(); + return at_detail(this); } + + template + static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + U value_at_impl(store*); }; template