Make fusion::at<vector<...>,N> O(1).

This commit is contained in:
Kohei Takahashi
2015-10-20 20:12:14 +09:00
parent c537da605b
commit 1ad2e59e07
3 changed files with 30 additions and 29 deletions

View File

@ -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

View File

@ -21,8 +21,9 @@
///////////////////////////////////////////////////////////////////////////////
// C++11 interface
///////////////////////////////////////////////////////////////////////////////
#include <cstddef>
#include <boost/fusion/container/vector/vector_fwd.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/type_traits/remove_cv.hpp>
namespace boost { namespace fusion
{
@ -42,23 +43,12 @@ namespace boost { namespace fusion
template <>
struct value_at_impl<vector_tag>
{
template <typename V, std::size_t N>
struct apply_impl;
template <typename H, typename ...T>
struct apply_impl<vector<H, T...>, 0>
{
typedef H type;
};
template <typename H, typename ...T, std::size_t N>
struct apply_impl<vector<H, T...>, N>
: apply_impl<vector<T...>, N - 1>
{};
template <typename Sequence, typename N>
struct apply : apply_impl<typename Sequence::type_sequence, N::value>
{};
struct apply
{
typedef typename boost::remove_cv<Sequence>::type seq;
typedef decltype(seq::template value_at_impl<N::value>(boost::declval<seq*>())) type;
};
};
}
}}

View File

@ -230,27 +230,37 @@ namespace boost { namespace fusion
assign(std::forward<Sequence>(seq), detail::index_sequence<M...>());
}
typedef extension::value_at_impl<vector_tag> value_at_impl;
template <std::size_t N, typename U>
static BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
auto at_detail(store<N, U>* this_) -> decltype(this_->get())
{
return this_->get();
}
template <std::size_t N, typename U>
static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
auto at_detail(store<N, U> const* this_) -> decltype(this_->get())
{
return this_->get();
}
template <typename J>
BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
typename value_at_impl::template apply<vector_data, J>::type&
at_impl(J)
auto at_impl(J) -> decltype(at_detail<J::value>(this))
{
typedef typename value_at_impl::template apply<vector_data, J>::type U;
typedef store<J::value, U> S;
return static_cast<S*>(this)->get();
return at_detail<J::value>(this);
}
template <typename J>
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
typename value_at_impl::template apply<vector_data, J>::type const&
at_impl(J) const
auto at_impl(J) const -> decltype(at_detail<J::value>(this))
{
typedef typename value_at_impl::template apply<vector_data, J>::type U;
typedef store<J::value, U> S;
return static_cast<S const*>(this)->get();
return at_detail<J::value>(this);
}
template <std::size_t N, typename U>
static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
U value_at_impl(store<N, U>*);
};
template <typename V, typename... T>