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 reference operator*() const; 15 // 16 // constexpr in C++17 17 18 // Be sure to respect LWG 198: 19 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198 20 // LWG 198 was superseded by LWG 2360 21 // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360 22 23 #include <iterator> 24 #include <cassert> 25 26 #include "test_macros.h" 27 28 class A 29 { 30 int data_; 31 public: A()32 A() : data_(1) {} ~A()33 ~A() {data_ = -1;} 34 operator ==(const A & x,const A & y)35 friend bool operator==(const A& x, const A& y) 36 {return x.data_ == y.data_;} 37 }; 38 39 template <class It> 40 void test(It i,typename std::iterator_traits<It>::value_type x)41test(It i, typename std::iterator_traits<It>::value_type x) 42 { 43 std::reverse_iterator<It> r(i); 44 assert(*r == x); 45 } 46 main()47int main() 48 { 49 A a; 50 test(&a+1, A()); 51 52 #if TEST_STD_VER > 14 53 { 54 constexpr const char *p = "123456789"; 55 typedef std::reverse_iterator<const char *> RI; 56 constexpr RI it1 = std::make_reverse_iterator(p+1); 57 constexpr RI it2 = std::make_reverse_iterator(p+2); 58 static_assert(*it1 == p[0], ""); 59 static_assert(*it2 == p[1], ""); 60 } 61 #endif 62 } 63