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 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
10 | |
11 | // <mdspan> |
12 | |
13 | // constexpr reference access(data_handle_type p, size_t i) const noexcept; |
14 | // |
15 | // Effects: Equivalent to: return p[i]; |
16 | |
17 | #include <mdspan> |
18 | #include <cassert> |
19 | #include <type_traits> |
20 | |
21 | #include "test_macros.h" |
22 | |
23 | #include "../MinimalElementType.h" |
24 | |
25 | template <class T> |
26 | constexpr void test_access() { |
27 | ElementPool<std::remove_const_t<T>, 10> data; |
28 | T* ptr = data.get_ptr(); |
29 | std::default_accessor<T> acc; |
30 | for(int i = 0; i < 10; i++) { |
31 | static_assert(std::is_same_v<decltype(acc.access(ptr, i)), typename std::default_accessor<T>::reference>); |
32 | ASSERT_NOEXCEPT(acc.access(ptr, i)); |
33 | assert(&acc.access(ptr, i) == ptr + i); |
34 | } |
35 | } |
36 | |
37 | constexpr bool test() { |
38 | test_access<int>(); |
39 | test_access<const int>(); |
40 | test_access<MinimalElementType>(); |
41 | test_access<const MinimalElementType>(); |
42 | return true; |
43 | } |
44 | |
45 | int main(int, char**) { |
46 | test(); |
47 | static_assert(test()); |
48 | return 0; |
49 | } |
50 | |