[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / views / views.span / span.iterators / rend.pass.cpp
blobffec15c6b2492cd0af8487e001896f1cedfd6853
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // <span>
12 // constexpr reverse_iterator rend() const noexcept;
13 // constexpr const_reverse_iterator crend() const noexcept;
15 #include <span>
16 #include <cassert>
17 #include <string>
19 #include "test_macros.h"
21 template <class Span>
22 constexpr bool testConstexprSpan(Span s)
24 bool ret = true;
25 typename Span::reverse_iterator e = s.rend();
26 if (s.empty())
28 ret = ret && (e == s.rbegin());
30 else
32 ret = ret && (e != s.rbegin());
35 ret = ret && (static_cast<std::size_t>(e - s.rbegin()) == s.size());
36 return ret;
39 template <class Span>
40 void testRuntimeSpan(Span s)
42 typename Span::reverse_iterator e = s.rend();
43 if (s.empty())
45 assert(e == s.rbegin());
47 else
49 assert(e != s.rbegin());
52 assert(static_cast<std::size_t>(e - s.rbegin()) == s.size());
56 struct A{};
57 bool operator==(A, A) {return true;}
59 constexpr int iArr1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
60 int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
63 int main(int, char**)
65 static_assert(testConstexprSpan(std::span<int>()), "");
66 static_assert(testConstexprSpan(std::span<long>()), "");
67 static_assert(testConstexprSpan(std::span<double>()), "");
68 static_assert(testConstexprSpan(std::span<A>()), "");
69 static_assert(testConstexprSpan(std::span<std::string>()), "");
71 static_assert(testConstexprSpan(std::span<int, 0>()), "");
72 static_assert(testConstexprSpan(std::span<long, 0>()), "");
73 static_assert(testConstexprSpan(std::span<double, 0>()), "");
74 static_assert(testConstexprSpan(std::span<A, 0>()), "");
75 static_assert(testConstexprSpan(std::span<std::string, 0>()), "");
77 static_assert(testConstexprSpan(std::span<const int>(iArr1, 1)), "");
78 static_assert(testConstexprSpan(std::span<const int>(iArr1, 2)), "");
79 static_assert(testConstexprSpan(std::span<const int>(iArr1, 3)), "");
80 static_assert(testConstexprSpan(std::span<const int>(iArr1, 4)), "");
81 static_assert(testConstexprSpan(std::span<const int>(iArr1, 5)), "");
84 testRuntimeSpan(std::span<int> ());
85 testRuntimeSpan(std::span<long> ());
86 testRuntimeSpan(std::span<double> ());
87 testRuntimeSpan(std::span<A> ());
88 testRuntimeSpan(std::span<std::string>());
90 testRuntimeSpan(std::span<int, 0> ());
91 testRuntimeSpan(std::span<long, 0> ());
92 testRuntimeSpan(std::span<double, 0> ());
93 testRuntimeSpan(std::span<A, 0> ());
94 testRuntimeSpan(std::span<std::string, 0>());
96 testRuntimeSpan(std::span<int>(iArr2, 1));
97 testRuntimeSpan(std::span<int>(iArr2, 2));
98 testRuntimeSpan(std::span<int>(iArr2, 3));
99 testRuntimeSpan(std::span<int>(iArr2, 4));
100 testRuntimeSpan(std::span<int>(iArr2, 5));
102 std::string s;
103 testRuntimeSpan(std::span<std::string>(&s, (std::size_t) 0));
104 testRuntimeSpan(std::span<std::string>(&s, 1));
106 return 0;