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 #include <iterator>
16 #include <cassert>
17
18 #include "test_iterators.h"
19
20 template <class It>
21 void
test(It i,typename std::iterator_traits<It>::difference_type n,It x)22 test(It i, typename std::iterator_traits<It>::difference_type n, It x)
23 {
24 assert(std::next(i, n) == x);
25 }
26
27 template <class It>
28 void
test(It i,It x)29 test(It i, It x)
30 {
31 assert(std::next(i) == x);
32 }
33
main()34 int main()
35 {
36 const char* s = "1234567890";
37 test(forward_iterator<const char*>(s), 10, forward_iterator<const char*>(s+10));
38 test(bidirectional_iterator<const char*>(s), 10, bidirectional_iterator<const char*>(s+10));
39 test(random_access_iterator<const char*>(s), 10, random_access_iterator<const char*>(s+10));
40 test(s, 10, s+10);
41
42 test(forward_iterator<const char*>(s), forward_iterator<const char*>(s+1));
43 test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1));
44 test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1));
45 test(s, s+1);
46 }
47