advance.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef BOOST_MPL_ADVANCE_HPP_INCLUDED
  2. #define BOOST_MPL_ADVANCE_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/advance_fwd.hpp>
  14. #include <boost/mpl/less.hpp>
  15. #include <boost/mpl/negate.hpp>
  16. #include <boost/mpl/long.hpp>
  17. #include <boost/mpl/if.hpp>
  18. #include <boost/mpl/tag.hpp>
  19. #include <boost/mpl/apply_wrap.hpp>
  20. #include <boost/mpl/aux_/advance_forward.hpp>
  21. #include <boost/mpl/aux_/advance_backward.hpp>
  22. #include <boost/mpl/aux_/value_wknd.hpp>
  23. #include <boost/mpl/aux_/na_spec.hpp>
  24. #include <boost/mpl/aux_/nttp_decl.hpp>
  25. namespace boost { namespace mpl {
  26. // default implementation for forward/bidirectional iterators
  27. template< typename Tag >
  28. struct advance_impl
  29. {
  30. template< typename Iterator, typename N > struct apply
  31. {
  32. typedef typename less< N,long_<0> >::type backward_;
  33. typedef typename if_< backward_, negate<N>, N >::type offset_;
  34. typedef typename if_<
  35. backward_
  36. , aux::advance_backward< BOOST_MPL_AUX_VALUE_WKND(offset_)::value >
  37. , aux::advance_forward< BOOST_MPL_AUX_VALUE_WKND(offset_)::value >
  38. >::type f_;
  39. typedef typename apply_wrap1<f_,Iterator>::type type;
  40. };
  41. };
  42. template<
  43. typename BOOST_MPL_AUX_NA_PARAM(Iterator)
  44. , typename BOOST_MPL_AUX_NA_PARAM(N)
  45. >
  46. struct advance
  47. : advance_impl< typename tag<Iterator>::type >
  48. ::template apply<Iterator,N>
  49. {
  50. };
  51. template<
  52. typename Iterator
  53. , BOOST_MPL_AUX_NTTP_DECL(long, N)
  54. >
  55. struct advance_c
  56. : advance_impl< typename tag<Iterator>::type >
  57. ::template apply<Iterator,long_<N> >
  58. {
  59. };
  60. BOOST_MPL_AUX_NA_SPEC(2, advance)
  61. }}
  62. #endif // BOOST_MPL_ADVANCE_HPP_INCLUDED