advance.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/advance.hpp>
  12. #include <boost/mpl/iterator_tags.hpp>
  13. #include <boost/mpl/aux_/test.hpp>
  14. template< int pos > struct iter
  15. {
  16. typedef mpl::bidirectional_iterator_tag category;
  17. typedef iter<(pos + 1)> next;
  18. typedef iter<(pos - 1)> prior;
  19. typedef int_<pos> type;
  20. };
  21. #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
  22. namespace boost { namespace mpl {
  23. template< int pos, typename Default > struct tag< iter<pos>,Default > : void_ {};
  24. }}
  25. #endif
  26. typedef iter<0> first;
  27. typedef iter<10> last;
  28. MPL_TEST_CASE()
  29. {
  30. typedef mpl::advance<first,int_<10> >::type iter1;
  31. typedef advance_c<first,10>::type iter2;
  32. MPL_ASSERT(( is_same<iter1, last> ));
  33. MPL_ASSERT(( is_same<iter2, last> ));
  34. }
  35. MPL_TEST_CASE()
  36. {
  37. typedef mpl::advance<last,int_<-10> >::type iter1;
  38. typedef advance_c<last,-10>::type iter2;
  39. MPL_ASSERT(( is_same<iter1, first> ));
  40. MPL_ASSERT(( is_same<iter2, first> ));
  41. }