Home | History | Annotate | Download | only in iterator.operations
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <iterator>
     11 
     12 // template <BidirectionalIterator Iter>
     13 //   Iter prev(Iter x, Iter::difference_type n = 1);
     14 
     15 #include <iterator>
     16 #include <cassert>
     17 
     18 #include "test_iterators.h"
     19 
     20 template <class It>
     21 void
     22 test(It i, typename std::iterator_traits<It>::difference_type n, It x)
     23 {
     24     assert(std::prev(i, n) == x);
     25 }
     26 
     27 template <class It>
     28 void
     29 test(It i, It x)
     30 {
     31     assert(std::prev(i) == x);
     32 }
     33 
     34 int main()
     35 {
     36     const char* s = "1234567890";
     37     test(bidirectional_iterator<const char*>(s+10), 10, bidirectional_iterator<const char*>(s));
     38     test(random_access_iterator<const char*>(s+10), 10, random_access_iterator<const char*>(s));
     39     test(s+10, 10, s);
     40 
     41     test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
     42     test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
     43     test(s+1, s);
     44 }
     45