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

source code of libcxx/test/std/containers/views/mdspan/MinimalElementType.h