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 // reverse_iterator 13 14 // requires RandomAccessIterator<Iter> 15 // unspecified operator[](difference_type n) const; 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,typename std::iterator_traits<It>::value_type x)24test(It i, typename std::iterator_traits<It>::difference_type n, 25 typename std::iterator_traits<It>::value_type x) 26 { 27 typedef typename std::iterator_traits<It>::value_type value_type; 28 const std::reverse_iterator<It> r(i); 29 value_type rr = r[n]; 30 assert(rr == x); 31 } 32 main()33int main() 34 { 35 const char* s = "1234567890"; 36 test(random_access_iterator<const char*>(s+5), 4, '1'); 37 test(s+5, 4, '1'); 38 } 39