build_std_tuple.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=============================================================================
  2. Copyright (c) 2014 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. #if !defined(BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100)
  7. #define BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/detail/index_sequence.hpp>
  10. #include <boost/fusion/iterator/equal_to.hpp>
  11. #include <boost/fusion/iterator/next.hpp>
  12. #include <boost/fusion/iterator/value_of.hpp>
  13. #include <boost/fusion/iterator/deref.hpp>
  14. #include <tuple>
  15. #include <cstddef>
  16. namespace boost { namespace fusion { namespace detail
  17. {
  18. template <typename First, typename Last,
  19. bool is_empty = result_of::equal_to<First, Last>::value>
  20. struct build_std_tuple;
  21. template <typename First, typename Last>
  22. struct build_std_tuple<First, Last, true>
  23. {
  24. typedef std::tuple<> type;
  25. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  26. static type
  27. call(First const&, Last const&)
  28. {
  29. return type();
  30. }
  31. };
  32. template <typename T, typename Rest>
  33. struct push_front_std_tuple;
  34. template <typename T, typename ...Rest>
  35. struct push_front_std_tuple<T, std::tuple<Rest...> >
  36. {
  37. typedef std::tuple<T, Rest...> type;
  38. template <std::size_t ...I>
  39. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  40. static type
  41. indexed_call(T const& first, std::tuple<Rest...> const& rest, index_sequence<I...>)
  42. {
  43. return type(first, std::get<I>(rest)...);
  44. }
  45. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  46. static type
  47. call(T const& first, std::tuple<Rest...> const& rest)
  48. {
  49. typedef typename make_index_sequence<sizeof...(Rest)>::type gen;
  50. return indexed_call(first, rest, gen());
  51. }
  52. };
  53. template <typename First, typename Last>
  54. struct build_std_tuple<First, Last, false>
  55. {
  56. typedef
  57. build_std_tuple<typename result_of::next<First>::type, Last>
  58. next_build_std_tuple;
  59. typedef push_front_std_tuple<
  60. typename result_of::value_of<First>::type
  61. , typename next_build_std_tuple::type>
  62. push_front;
  63. typedef typename push_front::type type;
  64. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  65. static type
  66. call(First const& f, Last const& l)
  67. {
  68. typename result_of::value_of<First>::type v = *f;
  69. return push_front::call(
  70. v, next_build_std_tuple::call(fusion::next(f), l));
  71. }
  72. };
  73. }}}
  74. #endif