distance.hpp 1.8 KB

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