| 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 |
|
| 25 |
class A |
| 26 |
{ |
| 27 |
int data_; |
| 28 |
public: |
| 29 |
A() : data_(1) {} |
| 30 |
A(const A&) = default; |
| 31 |
A& operator=(const A&) = default; |
| 32 |
~A() {data_ = -1;} |
| 33 |
|
| 34 |
friend bool operator==(const A& x, const A& y) |
| 35 |
{return x.data_ == y.data_;} |
| 36 |
}; |
| 37 |
|
| 38 |
template <class It> |
| 39 |
void |
| 40 |
test(It i, typename std::iterator_traits<It>::value_type x) |
| 41 |
{ |
| 42 |
std::reverse_iterator<It> r(i); |
| 43 |
assert(*r == x); |
| 44 |
} |
| 45 |
|
| 46 |
int main(int, char**) |
| 47 |
{ |
| 48 |
A a; |
| 49 |
test(&a+1, A()); |
| 50 |
|
| 51 |
#if TEST_STD_VER > 14 |
| 52 |
{ |
| 53 |
constexpr const char *p = "123456789"; |
| 54 |
typedef std::reverse_iterator<const char *> RI; |
| 55 |
constexpr RI it1 = std::make_reverse_iterator(p+1); |
| 56 |
constexpr RI it2 = std::make_reverse_iterator(p+2); |
| 57 |
static_assert(*it1 == p[0], ""); |
| 58 |
static_assert(*it2 == p[1], ""); |
| 59 |
} |
| 60 |
#endif |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |