ELF: Have __rela_iplt_{start,end} surround .rela.iplt with --pack-dyn-relocs=android.
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / iterators.common / iter_move.pass.cpp
blob8b3cbc9d14d3aeab498fd10d9aafe9439ebeb292
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 //===----------------------------------------------------------------------===//
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>;
15 #include <iterator>
16 #include <cassert>
17 #include <type_traits>
19 #include "test_iterators.h"
20 #include "test_macros.h"
22 struct IterMovingIt {
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&) {
33 return 42;
35 bool operator==(std::default_sentinel_t) const;
37 static_assert(std::input_iterator<IterMovingIt>);
39 constexpr bool test() {
41 using It = int*;
42 using CommonIt = std::common_iterator<It, sentinel_wrapper<It>>;
43 int a[] = {1, 2, 3};
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()) {
51 ++it;
52 assert(iter_move(it) == 2);
56 using It = const int*;
57 using CommonIt = std::common_iterator<It, sentinel_wrapper<It>>;
58 int a[] = {1, 2, 3};
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()) {
66 ++it;
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()) {
80 ++it;
81 assert(iter_move(it) == 42);
84 return true;
87 int main(int, char**) {
88 test();
89 static_assert(test());
91 return 0;