as_set.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_SET_11062014_2121
  7. #define FUSION_AS_SET_11062014_2121
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/container/set/set_fwd.hpp>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // Without variadics, we will use the PP version
  12. ///////////////////////////////////////////////////////////////////////////////
  13. #if !defined(BOOST_FUSION_HAS_VARIADIC_SET)
  14. # include <boost/fusion/container/set/detail/cpp03/as_set.hpp>
  15. #else
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // C++11 interface
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <boost/fusion/support/detail/index_sequence.hpp>
  20. #include <boost/fusion/container/set/set.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 <int size
  29. , typename = typename detail::make_index_sequence<size>::type>
  30. struct as_set;
  31. template <int size, std::size_t ...Indices>
  32. struct as_set<size, detail::index_sequence<Indices...> >
  33. {
  34. template <typename I>
  35. struct apply
  36. {
  37. typedef set<
  38. typename result_of::value_of<
  39. typename result_of::advance_c<I, Indices>::type
  40. >::type...
  41. > type;
  42. };
  43. template <typename Iterator>
  44. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  45. static typename apply<Iterator>::type
  46. call(Iterator const& i)
  47. {
  48. typedef apply<Iterator> gen;
  49. typedef typename gen::type result;
  50. return result(*advance_c<Indices>(i)...);
  51. }
  52. };
  53. BOOST_FUSION_BARRIER_END
  54. }}}
  55. #endif
  56. #endif