mpl_vector_to_tuple.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_DETAIL_MPL_VECTOR_TO_TUPLE_HPP
  11. #define BOOST_COMPUTE_DETAIL_MPL_VECTOR_TO_TUPLE_HPP
  12. #include <boost/mpl/copy.hpp>
  13. #include <boost/mpl/vector.hpp>
  14. #include <boost/tuple/tuple.hpp>
  15. #include <boost/fusion/include/mpl.hpp>
  16. #include <boost/fusion/adapted/boost_tuple.hpp>
  17. #include <boost/preprocessor/repetition.hpp>
  18. #include <boost/compute/config.hpp>
  19. namespace boost {
  20. namespace compute {
  21. namespace detail {
  22. namespace mpl = boost::mpl;
  23. template<class Vector, size_t N>
  24. struct mpl_vector_to_tuple_impl;
  25. #define BOOST_COMPUTE_PRINT_ELEM(z, n, unused) \
  26. typename mpl::at_c<Vector, n>::type
  27. #define BOOST_COMPUTE_VEC2TUP(z, n, unused) \
  28. template<class Vector> \
  29. struct mpl_vector_to_tuple_impl<Vector, n> \
  30. { \
  31. typedef typename \
  32. boost::tuple< \
  33. BOOST_PP_ENUM(n, BOOST_COMPUTE_PRINT_ELEM, ~) \
  34. > type; \
  35. };
  36. BOOST_PP_REPEAT_FROM_TO(1, BOOST_COMPUTE_MAX_ARITY, BOOST_COMPUTE_VEC2TUP, ~)
  37. #undef BOOST_COMPUTE_VEC2TUP
  38. #undef BOOST_COMPUTE_PRINT_ELEM
  39. // meta-function which converts a mpl::vector to a boost::tuple
  40. template<class Vector>
  41. struct mpl_vector_to_tuple
  42. {
  43. typedef typename
  44. mpl_vector_to_tuple_impl<
  45. Vector,
  46. mpl::size<Vector>::value
  47. >::type type;
  48. };
  49. } // end detail namespace
  50. } // end compute namespace
  51. } // end boost namespace
  52. #endif // BOOST_COMPUTE_DETAIL_MPL_VECTOR_TO_TUPLE_HPP