distance.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef BOOST_MPL_DISTANCE_HPP_INCLUDED
  2. #define BOOST_MPL_DISTANCE_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/distance_fwd.hpp>
  14. #include <boost/mpl/iter_fold.hpp>
  15. #include <boost/mpl/iterator_range.hpp>
  16. #include <boost/mpl/long.hpp>
  17. #include <boost/mpl/next.hpp>
  18. #include <boost/mpl/tag.hpp>
  19. #include <boost/mpl/apply_wrap.hpp>
  20. #include <boost/mpl/aux_/msvc_eti_base.hpp>
  21. #include <boost/mpl/aux_/value_wknd.hpp>
  22. #include <boost/mpl/aux_/na_spec.hpp>
  23. #include <boost/mpl/aux_/config/forwarding.hpp>
  24. #include <boost/mpl/aux_/config/static_constant.hpp>
  25. namespace boost { namespace mpl {
  26. // default implementation for forward/bidirectional iterators
  27. template< typename Tag > struct distance_impl
  28. {
  29. template< typename First, typename Last > struct apply
  30. #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
  31. : aux::msvc_eti_base< typename iter_fold<
  32. iterator_range<First,Last>
  33. , mpl::long_<0>
  34. , next<>
  35. >::type >
  36. {
  37. #else
  38. {
  39. typedef typename iter_fold<
  40. iterator_range<First,Last>
  41. , mpl::long_<0>
  42. , next<>
  43. >::type type;
  44. BOOST_STATIC_CONSTANT(long, value =
  45. (iter_fold<
  46. iterator_range<First,Last>
  47. , mpl::long_<0>
  48. , next<>
  49. >::type::value)
  50. );
  51. #endif
  52. };
  53. };
  54. template<
  55. typename BOOST_MPL_AUX_NA_PARAM(First)
  56. , typename BOOST_MPL_AUX_NA_PARAM(Last)
  57. >
  58. struct distance
  59. : distance_impl< typename tag<First>::type >
  60. ::template apply<First, Last>
  61. {
  62. BOOST_MPL_AUX_LAMBDA_SUPPORT(2, distance, (First, Last))
  63. };
  64. BOOST_MPL_AUX_NA_SPEC(2, distance)
  65. }}
  66. #endif // BOOST_MPL_DISTANCE_HPP_INCLUDED