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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // friend iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
12 // noexcept(noexcept(ranges::iter_move(declval<const I&>())))
13 // requires input_iterator<I>;
17 #include <type_traits>
19 #include "test_iterators.h"
20 #include "test_macros.h"
23 using value_type
= int;
24 using difference_type
= int;
25 explicit IterMovingIt() = default;
26 IterMovingIt(const IterMovingIt
&); // copyable, but this test shouldn't make copies
27 IterMovingIt(IterMovingIt
&&) = default;
28 IterMovingIt
& operator=(const IterMovingIt
&);
29 int& operator*() const;
30 constexpr IterMovingIt
& operator++() { return *this; }
31 IterMovingIt
operator++(int);
32 friend constexpr int iter_move(const IterMovingIt
&) {
35 bool operator==(std::default_sentinel_t
) const;
37 static_assert(std::input_iterator
<IterMovingIt
>);
39 constexpr bool test() {
42 using CommonIt
= std::common_iterator
<It
, sentinel_wrapper
<It
>>;
44 CommonIt it
= CommonIt(It(a
));
45 ASSERT_NOEXCEPT(iter_move(it
));
46 ASSERT_NOEXCEPT(std::ranges::iter_move(it
));
47 ASSERT_SAME_TYPE(decltype(iter_move(it
)), int&&);
48 ASSERT_SAME_TYPE(decltype(std::ranges::iter_move(it
)), int&&);
49 assert(iter_move(it
) == 1);
50 if (!std::is_constant_evaluated()) {
52 assert(iter_move(it
) == 2);
56 using It
= const int*;
57 using CommonIt
= std::common_iterator
<It
, sentinel_wrapper
<It
>>;
59 CommonIt it
= CommonIt(It(a
));
60 ASSERT_NOEXCEPT(iter_move(it
));
61 ASSERT_NOEXCEPT(std::ranges::iter_move(it
));
62 ASSERT_SAME_TYPE(decltype(iter_move(it
)), const int&&);
63 ASSERT_SAME_TYPE(decltype(std::ranges::iter_move(it
)), const int&&);
64 assert(iter_move(it
) == 1);
65 if (!std::is_constant_evaluated()) {
67 assert(iter_move(it
) == 2);
71 using It
= IterMovingIt
;
72 using CommonIt
= std::common_iterator
<It
, std::default_sentinel_t
>;
73 CommonIt it
= CommonIt(It());
74 ASSERT_NOT_NOEXCEPT(iter_move(it
));
75 ASSERT_NOT_NOEXCEPT(std::ranges::iter_move(it
));
76 ASSERT_SAME_TYPE(decltype(iter_move(it
)), int);
77 ASSERT_SAME_TYPE(decltype(std::ranges::iter_move(it
)), int);
78 assert(iter_move(it
) == 42);
79 if (!std::is_constant_evaluated()) {
81 assert(iter_move(it
) == 42);
87 int main(int, char**) {
89 static_assert(test());