convert_iterator.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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(FUSION_CONVERT_ITERATOR_05062005_1218)
  7. #define FUSION_CONVERT_ITERATOR_05062005_1218
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/fusion/support/is_iterator.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. namespace boost { namespace fusion
  13. {
  14. template <typename Iterator>
  15. struct mpl_iterator; // forward declaration
  16. // Test T. If it is a fusion iterator, return a reference to it.
  17. // else, assume it is an mpl iterator.
  18. template <typename T>
  19. struct convert_iterator
  20. {
  21. typedef typename
  22. mpl::if_<
  23. is_fusion_iterator<T>
  24. , T
  25. , mpl_iterator<T>
  26. >::type
  27. type;
  28. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  29. static T const&
  30. call(T const& x, mpl::true_)
  31. {
  32. return x;
  33. }
  34. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  35. static mpl_iterator<T>
  36. call(T const& /*x*/, mpl::false_)
  37. {
  38. return mpl_iterator<T>();
  39. }
  40. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  41. static typename
  42. mpl::if_<
  43. is_fusion_iterator<T>
  44. , T const&
  45. , mpl_iterator<T>
  46. >::type
  47. call(T const& x)
  48. {
  49. return call(x, is_fusion_iterator<T>());
  50. }
  51. };
  52. }}
  53. #endif