[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / libcxx / test / std / containers / views / span.obs / size_bytes.pass.cpp
blob1cd3b69431c2de0c091bc9e75505b243afca72ad
1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===---------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
11 // <span>
13 // constexpr size_type size_bytes() const noexcept;
15 // Effects: Equivalent to: return size() * sizeof(element_type);
18 #include <span>
19 #include <cassert>
20 #include <string>
22 #include "test_macros.h"
25 template <typename Span>
26 constexpr bool testConstexprSpan(Span sp, size_t sz)
28 ASSERT_NOEXCEPT(sp.size_bytes());
29 return (size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type);
33 template <typename Span>
34 void testRuntimeSpan(Span sp, size_t sz)
36 ASSERT_NOEXCEPT(sp.size_bytes());
37 assert((size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type));
40 struct A{};
41 constexpr int iArr1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
42 int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
44 int main(int, char**)
46 static_assert(testConstexprSpan(std::span<int>(), 0), "");
47 static_assert(testConstexprSpan(std::span<long>(), 0), "");
48 static_assert(testConstexprSpan(std::span<double>(), 0), "");
49 static_assert(testConstexprSpan(std::span<A>(), 0), "");
50 static_assert(testConstexprSpan(std::span<std::string>(), 0), "");
52 static_assert(testConstexprSpan(std::span<int, 0>(), 0), "");
53 static_assert(testConstexprSpan(std::span<long, 0>(), 0), "");
54 static_assert(testConstexprSpan(std::span<double, 0>(), 0), "");
55 static_assert(testConstexprSpan(std::span<A, 0>(), 0), "");
56 static_assert(testConstexprSpan(std::span<std::string, 0>(), 0), "");
58 static_assert(testConstexprSpan(std::span<const int>(iArr1, 1), 1), "");
59 static_assert(testConstexprSpan(std::span<const int>(iArr1, 2), 2), "");
60 static_assert(testConstexprSpan(std::span<const int>(iArr1, 3), 3), "");
61 static_assert(testConstexprSpan(std::span<const int>(iArr1, 4), 4), "");
62 static_assert(testConstexprSpan(std::span<const int>(iArr1, 5), 5), "");
64 testRuntimeSpan(std::span<int> (), 0);
65 testRuntimeSpan(std::span<long> (), 0);
66 testRuntimeSpan(std::span<double> (), 0);
67 testRuntimeSpan(std::span<A> (), 0);
68 testRuntimeSpan(std::span<std::string>(), 0);
70 testRuntimeSpan(std::span<int, 0> (), 0);
71 testRuntimeSpan(std::span<long, 0> (), 0);
72 testRuntimeSpan(std::span<double, 0> (), 0);
73 testRuntimeSpan(std::span<A, 0> (), 0);
74 testRuntimeSpan(std::span<std::string, 0>(), 0);
76 testRuntimeSpan(std::span<int>(iArr2, 1), 1);
77 testRuntimeSpan(std::span<int>(iArr2, 2), 2);
78 testRuntimeSpan(std::span<int>(iArr2, 3), 3);
79 testRuntimeSpan(std::span<int>(iArr2, 4), 4);
80 testRuntimeSpan(std::span<int>(iArr2, 5), 5);
82 testRuntimeSpan(std::span<int, 1>(iArr2 + 5, 1), 1);
83 testRuntimeSpan(std::span<int, 2>(iArr2 + 4, 2), 2);
84 testRuntimeSpan(std::span<int, 3>(iArr2 + 3, 3), 3);
85 testRuntimeSpan(std::span<int, 4>(iArr2 + 2, 4), 4);
86 testRuntimeSpan(std::span<int, 5>(iArr2 + 1, 5), 5);
88 std::string s;
89 testRuntimeSpan(std::span<std::string>(&s, (std::size_t) 0), 0);
90 testRuntimeSpan(std::span<std::string>(&s, 1), 1);
92 return 0;