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