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_macros.h" 21#include "test_iterators.h" 22 23template <class It> 24void 25test(It i, typename std::iterator_traits<It>::difference_type n, 26 typename std::iterator_traits<It>::value_type x) 27{ 28 typedef typename std::iterator_traits<It>::value_type value_type; 29 const std::reverse_iterator<It> r(i); 30 value_type rr = r[n]; 31 assert(rr == x); 32} 33 34int main() 35{ 36 const char* s = "1234567890"; 37 test(random_access_iterator<const char*>(s+5), 4, '1'); 38 test(s+5, 4, '1'); 39 40#if TEST_STD_VER > 14 41 { 42 constexpr const char *p = "123456789"; 43 typedef std::reverse_iterator<const char *> RI; 44 constexpr RI it1 = std::make_reverse_iterator(p + 5); 45 static_assert(it1[0] == '5', ""); 46 static_assert(it1[4] == '1', ""); 47 } 48#endif 49} 50