distance.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_DISTANCE_09172005_0730)
  7. #define FUSION_DISTANCE_09172005_0730
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/mpl/int.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/eval_if.hpp>
  12. #include <boost/mpl/next.hpp>
  13. #include <boost/mpl/identity.hpp>
  14. #include <boost/fusion/iterator/next.hpp>
  15. #include <boost/fusion/iterator/equal_to.hpp>
  16. namespace boost { namespace fusion { namespace distance_detail
  17. {
  18. // Default distance implementation, linear
  19. // search for the Last iterator.
  20. template <typename First, typename Last>
  21. struct linear_distance;
  22. template <typename First, typename Last>
  23. struct next_distance
  24. {
  25. typedef typename
  26. mpl::next<
  27. typename linear_distance<
  28. typename result_of::next<First>::type
  29. , Last
  30. >::type
  31. >::type
  32. type;
  33. };
  34. template <typename First, typename Last>
  35. struct linear_distance
  36. : mpl::eval_if<
  37. result_of::equal_to<First, Last>
  38. , mpl::identity<mpl::int_<0> >
  39. , next_distance<First, Last>
  40. >::type
  41. {
  42. typedef typename
  43. mpl::eval_if<
  44. result_of::equal_to<First, Last>
  45. , mpl::identity<mpl::int_<0> >
  46. , next_distance<First, Last>
  47. >::type
  48. type;
  49. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  50. static type
  51. call(First const&, Last const&)
  52. {
  53. return type();
  54. }
  55. };
  56. }}}
  57. #endif