1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
14 // reverse_iterator& operator=(const reverse_iterator<U>& u); // constexpr since C++17
19 #include "test_macros.h"
20 #include "test_iterators.h"
22 template <class It
, class U
>
23 TEST_CONSTEXPR_CXX17
void test(U u
) {
24 const std::reverse_iterator
<U
> r2(u
);
25 std::reverse_iterator
<It
> r1
;
26 std::reverse_iterator
<It
>& rr
= r1
= r2
;
27 assert(base(r1
.base()) == base(u
));
32 struct Derived
: Base
{ };
35 typedef std::bidirectional_iterator_tag iterator_category
;
36 typedef char *pointer
;
37 typedef char &reference
;
38 typedef char value_type
;
39 typedef value_type difference_type
;
41 explicit TEST_CONSTEXPR_CXX17
ToIter() : m_value(0) {}
42 TEST_CONSTEXPR_CXX17
ToIter(const ToIter
&src
) : m_value(src
.m_value
) {}
43 // Intentionally not defined, must not be called.
45 TEST_CONSTEXPR_CXX17 ToIter
&operator=(char *src
) {
49 TEST_CONSTEXPR_CXX17 ToIter
&operator=(const ToIter
&src
) {
50 m_value
= src
.m_value
;
55 reference
operator*() const;
58 TEST_CONSTEXPR_CXX17
bool tests() {
60 test
<bidirectional_iterator
<Base
*> >(bidirectional_iterator
<Derived
*>(&d
));
61 test
<random_access_iterator
<const Base
*> >(random_access_iterator
<Derived
*>(&d
));
66 const std::reverse_iterator
<char *> rev_fi(fi
);
67 std::reverse_iterator
<ToIter
> rev_ti
;
69 assert(rev_ti
.base().m_value
== fi
);
74 int main(int, char**) {
77 static_assert(tests(), "");