// SPDX-FileCopyrightText: 2021 Jorrit Rouwe // SPDX-License-Identifier: MIT #pragma once JPH_NAMESPACE_BEGIN /// STL allocator that takes care that memory is aligned to N bytes template class STLAlignedAllocator { public: using value_type = T; /// Pointer to type using pointer = T *; using const_pointer = const T *; /// Reference to type. /// Can be removed in C++20. using reference = T &; using const_reference = const T &; using size_type = size_t; using difference_type = ptrdiff_t; /// Constructor inline STLAlignedAllocator() = default; /// Constructor from other allocator template inline explicit STLAlignedAllocator(const STLAlignedAllocator &) { } /// Allocate memory inline pointer allocate(size_type inN) { return (pointer)AlignedAllocate(inN * sizeof(value_type), N); } /// Free memory inline void deallocate(pointer inPointer, size_type) { AlignedFree(inPointer); } /// Allocators are stateless so assumed to be equal inline bool operator == (const STLAlignedAllocator &) const { return true; } inline bool operator != (const STLAlignedAllocator &) const { return false; } /// Converting to allocator for other type template struct rebind { using other = STLAlignedAllocator; }; }; JPH_NAMESPACE_END