| 395 | */ |
| 396 | template <typename type_> |
| 397 | class aligned_array { |
| 398 | |
| 399 | type_ *data_ = nullptr; |
| 400 | std::size_t size_ = 0; |
| 401 | std::size_t alignment_ = 0; |
| 402 | |
| 403 | public: |
| 404 | aligned_array(std::size_t size, std::size_t alignment = 64) : size_(size), alignment_(alignment) { |
| 405 | // With `std::aligned_alloc` in C++17, an exception won't be raised, which may be preferred in |
| 406 | // some environments. MSVC was late to adopt it, and developers would often use a combination |
| 407 | // of lower-level `posix_memalign` and `_aligned_malloc`/`_aligned_free` across Unix and Windows. |
| 408 | data_ = (type_ *)::operator new(sizeof(type_) * size_, std::align_val_t(alignment_)); |
| 409 | } |
| 410 | ~aligned_array() noexcept { ::operator delete(data_, sizeof(type_) * size_, std::align_val_t(alignment_)); } |
| 411 | |
| 412 | aligned_array(aligned_array const &) = delete; |
| 413 | aligned_array &operator=(aligned_array const &) = delete; |
| 414 | aligned_array(aligned_array &&) = delete; |
| 415 | aligned_array &operator=(aligned_array &&) = delete; |
| 416 | |
| 417 | type_ *begin() const noexcept { return data_; } |
| 418 | type_ *end() const noexcept { return data_ + size_; } |
| 419 | type_ &operator[](std::size_t index) noexcept { return data_[index]; } |
| 420 | type_ operator[](std::size_t index) const noexcept { return data_[index]; } |
| 421 | }; |
| 422 | |
| 423 | static void sorting(bm::State &state) { |
| 424 |
nothing calls this directly
no outgoing calls
no test coverage detected