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 20template <class It> 21void 22test(It i, typename std::iterator_traits<It>::difference_type n, It x) 23{ 24 assert(std::prev(i, n) == x); 25} 26 27template <class It> 28void 29test(It i, It x) 30{ 31 assert(std::prev(i) == x); 32} 33 34int 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