mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-24 01:27:37 +02:00
Make fusion::at<vector<...>,N> O(1).
This commit is contained in:
@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
#if (defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \
|
#if (defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \
|
||||||
|| defined(BOOST_NO_CXX11_RVALUE_REFERENCES) \
|
|| 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))
|
|| (defined(__WAVE__) && defined(BOOST_FUSION_CREATE_PREPROCESSED_FILES))
|
||||||
# if defined(BOOST_FUSION_HAS_VARIADIC_VECTOR)
|
# if defined(BOOST_FUSION_HAS_VARIADIC_VECTOR)
|
||||||
# undef BOOST_FUSION_HAS_VARIADIC_VECTOR
|
# undef BOOST_FUSION_HAS_VARIADIC_VECTOR
|
||||||
|
@ -21,8 +21,9 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// C++11 interface
|
// C++11 interface
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#include <cstddef>
|
|
||||||
#include <boost/fusion/container/vector/vector_fwd.hpp>
|
#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
|
namespace boost { namespace fusion
|
||||||
{
|
{
|
||||||
@ -42,23 +43,12 @@ namespace boost { namespace fusion
|
|||||||
template <>
|
template <>
|
||||||
struct value_at_impl<vector_tag>
|
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>
|
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;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -230,27 +230,37 @@ namespace boost { namespace fusion
|
|||||||
assign(std::forward<Sequence>(seq), detail::index_sequence<M...>());
|
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>
|
template <typename J>
|
||||||
BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
||||||
typename value_at_impl::template apply<vector_data, J>::type&
|
auto at_impl(J) -> decltype(at_detail<J::value>(this))
|
||||||
at_impl(J)
|
|
||||||
{
|
{
|
||||||
typedef typename value_at_impl::template apply<vector_data, J>::type U;
|
return at_detail<J::value>(this);
|
||||||
typedef store<J::value, U> S;
|
|
||||||
return static_cast<S*>(this)->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename J>
|
template <typename J>
|
||||||
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
||||||
typename value_at_impl::template apply<vector_data, J>::type const&
|
auto at_impl(J) const -> decltype(at_detail<J::value>(this))
|
||||||
at_impl(J) const
|
|
||||||
{
|
{
|
||||||
typedef typename value_at_impl::template apply<vector_data, J>::type U;
|
return at_detail<J::value>(this);
|
||||||
typedef store<J::value, U> S;
|
|
||||||
return static_cast<S const*>(this)->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
template <typename V, typename... T>
|
||||||
|
Reference in New Issue
Block a user