This implements default_accessor and its tests for mdspan.
Details
- Reviewers
ldionne - Group Reviewers
Restricted Project - Commits
- rG20c6b9d451ca: [libc++][mdspan] Implement default_accessor
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
| libcxx/test/std/containers/views/mdspan/MinimalElementType.h | ||
|---|---|---|
| 19 | ||
| 24–40 | Let's make this all work at compile-time instead (https://godbolt.org/z/EshfM1rzn): #include <memory>
struct MinimalElementType {
int val;
constexpr MinimalElementType() = delete;
constexpr MinimalElementType(const MinimalElementType&) = delete;
constexpr explicit MinimalElementType(int v) noexcept : val(v) {}
constexpr MinimalElementType& operator=(const MinimalElementType&) = delete;
};
// Helper class to create pointer of MinimalElementType
template<class T, size_t N>
struct ElementPool {
constexpr ElementPool() {
ptr_ = std::allocator<T>().allocate(N);
for (int i = 0; i != N; ++i)
std::construct_at(ptr_ + i, 42);
}
constexpr T* get_ptr() { return ptr_; }
constexpr ~ElementPool() {
for (int i = 0; i != N; ++i)
std::destroy_at(ptr_ + i);
std::allocator<T>().deallocate(ptr_, N);
}
private:
T* ptr_;
};
constexpr bool f() {
ElementPool<MinimalElementType, 128> pool;
MinimalElementType* p = pool.get_ptr();
return true;
}
int main() {
f();
static_assert(f());
} | |
| libcxx/test/std/containers/views/mdspan/default_accessor/access.pass.cpp | ||
| 31 | Everywhere! | |
| 34 | ||
| 41 | This won't be true anymore, we can run these tests always. | |
| libcxx/test/std/containers/views/mdspan/default_accessor/ctor.conversion.pass.cpp | ||
| 30–34 | I don't find that the _t typedefs help readability. I think we should remove them. | |
| 53 | Maybe add some sort of base/derived case here? | |
| libcxx/test/std/containers/views/mdspan/default_accessor/ctor.default.pass.cpp | ||
| 28 | Do we want to add static_assert(std::is_trivially_default_constructible)? This would test that this is = default. | |
| libcxx/test/std/containers/views/mdspan/default_accessor/element_type.verify.cpp | ||
| 8 | ||
| libcxx/test/std/containers/views/mdspan/default_accessor/offset.pass.cpp | ||
| 26 | This function name is wrong. Probably happens elsewhere too. | |
| 27–28 | This comment isn't super useful IMO | |
| 34 | ||
For the 3 macros within this file.