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 | #ifndef TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H |
10 | #define TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H |
11 | |
12 | #include <memory> |
13 | #include <type_traits> |
14 | |
15 | // Idiosyncratic element type for mdspan |
16 | // Make sure we don't assume copyable, default constructible, movable etc. |
17 | struct MinimalElementType { |
18 | int val; |
19 | constexpr MinimalElementType() = delete; |
20 | constexpr MinimalElementType(const MinimalElementType&) = delete; |
21 | constexpr explicit MinimalElementType(int v) noexcept : val(v){} |
22 | constexpr MinimalElementType& operator=(const MinimalElementType&) = delete; |
23 | }; |
24 | |
25 | // Helper class to create pointer to MinimalElementType |
26 | template<class T, size_t N> |
27 | struct ElementPool { |
28 | constexpr ElementPool() { |
29 | ptr_ = std::allocator<std::remove_const_t<T>>().allocate(N); |
30 | for (int i = 0; i != N; ++i) |
31 | std::construct_at(ptr_ + i, 42); |
32 | } |
33 | |
34 | constexpr T* get_ptr() { return ptr_; } |
35 | |
36 | constexpr ~ElementPool() { |
37 | for (int i = 0; i != N; ++i) |
38 | std::destroy_at(ptr_ + i); |
39 | std::allocator<std::remove_const_t<T>>().deallocate(ptr_, N); |
40 | } |
41 | |
42 | private: |
43 | std::remove_const_t<T>* ptr_; |
44 | }; |
45 | |
46 | #endif // TEST_STD_CONTAINERS_VIEWS_MDSPAN_MINIMAL_ELEMENT_TYPE_H |
47 | |