as_vector.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*=============================================================================
  2. Copyright (c) 2014-2015 Kohei Takahashi
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #ifndef FUSION_AS_VECTOR_11052014_1801
  7. #define FUSION_AS_VECTOR_11052014_1801
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/vector/detail/config.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // Without variadics, we will use the PP version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_VECTOR)
  14. # include <boost/fusion/container/vector/detail/cpp03/as_vector.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <boost/fusion/support/detail/index_sequence.hpp>
  20. #include <boost/fusion/container/vector/vector.hpp>
  21. #include <boost/fusion/iterator/value_of.hpp>
  22. #include <boost/fusion/iterator/deref.hpp>
  23. #include <boost/fusion/iterator/advance.hpp>
  24. #include <cstddef>
  25. namespace boost { namespace fusion { namespace detail
  26. {
  27. BOOST_FUSION_BARRIER_BEGIN
  28. template <typename Indices>
  29. struct as_vector_impl;
  30. template <std::size_t ...Indices>
  31. struct as_vector_impl<index_sequence<Indices...> >
  32. {
  33. template <typename Iterator>
  34. struct apply
  35. {
  36. typedef vector<
  37. typename result_of::value_of<
  38. typename result_of::advance_c<Iterator, Indices>::type
  39. >::type...
  40. > type;
  41. };
  42. template <typename Iterator>
  43. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  44. static typename apply<Iterator>::type
  45. call(Iterator i)
  46. {
  47. typedef typename apply<Iterator>::type result;
  48. return result(*advance_c<Indices>(i)...);
  49. }
  50. };
  51. template <int size>
  52. struct as_vector
  53. : as_vector_impl<typename make_index_sequence<size>::type> {};
  54. BOOST_FUSION_BARRIER_END
  55. }}}
  56. #endif
  57. #endif