• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <InputIterator Iter>
13 //   Iter next(Iter x, Iter::difference_type n = 1);
14 
15 // LWG #2353 relaxed the requirement on next from ForwardIterator to InputIterator
16 
17 #include <iterator>
18 #include <cassert>
19 
20 #include "test_iterators.h"
21 
22 template <class It>
23 void
test(It i,typename std::iterator_traits<It>::difference_type n,It x)24 test(It i, typename std::iterator_traits<It>::difference_type n, It x)
25 {
26     assert(std::next(i, n) == x);
27 }
28 
29 template <class It>
30 void
test(It i,It x)31 test(It i, It x)
32 {
33     assert(std::next(i) == x);
34 }
35 
main()36 int main()
37 {
38     const char* s = "1234567890";
39     test(input_iterator<const char*>(s), 10, input_iterator<const char*>(s+10));
40     test(forward_iterator<const char*>(s), 10, forward_iterator<const char*>(s+10));
41     test(bidirectional_iterator<const char*>(s), 10, bidirectional_iterator<const char*>(s+10));
42     test(random_access_iterator<const char*>(s), 10, random_access_iterator<const char*>(s+10));
43     test(s, 10, s+10);
44 
45     test(input_iterator<const char*>(s), input_iterator<const char*>(s+1));
46     test(forward_iterator<const char*>(s), forward_iterator<const char*>(s+1));
47     test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1));
48     test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1));
49     test(s, s+1);
50 }
51