at_impl.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(FUSION_AT_IMPL_20060124_1933)
  8. #define FUSION_AT_IMPL_20060124_1933
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/container/vector.hpp>
  11. #include <boost/fusion/sequence/intrinsic/at.hpp>
  12. #include <boost/fusion/container/vector/convert.hpp>
  13. #include <boost/fusion/algorithm/transformation/transform.hpp>
  14. #include <boost/type_traits/remove_reference.hpp>
  15. #include <boost/type_traits/is_reference.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include <boost/fusion/support/unused.hpp>
  18. #include <boost/mpl/eval_if.hpp>
  19. #include <boost/mpl/identity.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. namespace boost { namespace fusion
  22. {
  23. struct zip_view_tag;
  24. namespace detail
  25. {
  26. template<typename N>
  27. struct poly_at
  28. {
  29. template<typename T>
  30. struct result;
  31. template<typename N1, typename SeqRef>
  32. struct result<poly_at<N1>(SeqRef)>
  33. : mpl::eval_if<is_same<SeqRef, unused_type const&>,
  34. mpl::identity<unused_type>,
  35. result_of::at<typename remove_reference<SeqRef>::type, N> >
  36. {
  37. BOOST_MPL_ASSERT((is_reference<SeqRef>));
  38. };
  39. template<typename Seq>
  40. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  41. typename result<poly_at(Seq&)>::type
  42. operator()(Seq& seq) const
  43. {
  44. return fusion::at<N>(seq);
  45. }
  46. template<typename Seq>
  47. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. typename result<poly_at(Seq const&)>::type
  49. operator()(Seq const& seq) const
  50. {
  51. return fusion::at<N>(seq);
  52. }
  53. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  54. unused_type operator()(unused_type const&) const
  55. {
  56. return unused_type();
  57. }
  58. };
  59. }
  60. namespace extension
  61. {
  62. template<typename Tag>
  63. struct at_impl;
  64. template<>
  65. struct at_impl<zip_view_tag>
  66. {
  67. template<typename Seq, typename N>
  68. struct apply
  69. {
  70. typedef typename result_of::as_vector<
  71. typename result_of::transform<
  72. typename Seq::sequences, detail::poly_at<N> >::type>::type type;
  73. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  74. static type
  75. call(Seq& seq)
  76. {
  77. return type(
  78. fusion::transform(seq.sequences_, detail::poly_at<N>()));
  79. }
  80. };
  81. };
  82. }
  83. }}
  84. #endif