1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <iterator>
10
11// reverse_iterator
12
13// reference operator*() const; // constexpr in C++17
14
15// Be sure to respect LWG 198:
16// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
17// LWG 198 was superseded by LWG 2360
18// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
19
20#include <iterator>
21#include <cassert>
22
23#include "test_macros.h"
24#include "test_iterators.h"
25
26class A
27{
28 int data_;
29public:
30 A() : data_(1) {}
31 A(const A&) = default;
32 A& operator=(const A&) = default;
33 ~A() {data_ = -1;}
34
35 friend bool operator==(const A& x, const A& y)
36 {return x.data_ == y.data_;}
37};
38
39template <class It>
40void
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
47int main(int, char**)
48{
49 A a;
50 test(i: &a+1, x: A());
51 test(random_access_iterator<A*>(&a + 1), A());
52#if TEST_STD_VER >= 20
53 test(cpp20_random_access_iterator<A*>(&a + 1), A());
54#endif
55
56#if TEST_STD_VER > 14
57 {
58 constexpr const char *p = "123456789";
59 typedef std::reverse_iterator<const char *> RI;
60 constexpr RI it1 = std::make_reverse_iterator(p+1);
61 constexpr RI it2 = std::make_reverse_iterator(p+2);
62 static_assert(*it1 == p[0], "");
63 static_assert(*it2 == p[1], "");
64 }
65#endif
66
67 return 0;
68}
69

source code of libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp