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 // constexpr reverse_iterator& operator++(); 15 // 16 // constexpr in c++17 17 18 #include <iterator> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 24 template <class It> 25 void 26 test(It i, It x) 27 { 28 std::reverse_iterator<It> r(i); 29 std::reverse_iterator<It>& rr = ++r; 30 assert(r.base() == x); 31 assert(&rr == &r); 32 } 33 34 int main() 35 { 36 const char* s = "123"; 37 test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s)); 38 test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s)); 39 test(s+1, s); 40 41 #if TEST_STD_VER > 14 42 { 43 constexpr const char *p = "123456789"; 44 typedef std::reverse_iterator<const char *> RI; 45 constexpr RI it1 = std::make_reverse_iterator(p); 46 constexpr RI it2 = std::make_reverse_iterator(p+1); 47 static_assert(it1 != it2, ""); 48 constexpr RI it3 = ++ std::make_reverse_iterator(p+1); 49 static_assert(it1 == it3, ""); 50 static_assert(it2 != it3, ""); 51 static_assert(*(++std::make_reverse_iterator(p+2)) == '1', ""); 52 } 53 #endif 54 } 55