#pragma once #if !defined(MIJIN_MEMORY_VIRTUAL_ALLOCATOR_HPP_INCLUDED) #define MIJIN_MEMORY_VIRTUAL_ALLOCATOR_HPP_INCLUDED 1 #include "../internal/common.hpp" #include "../util/annot.hpp" namespace mijin { template class VirtualAllocator { public: virtual ~VirtualAllocator() noexcept = default; [[nodiscard]] virtual owner_t allocate(std::size_t count) noexcept; virtual void deallocate(owner_t ptr, std::size_t count) noexcept; }; template class WrappedVirtualAllocator : public VirtualAllocator { private: [[no_unique_address]] TImpl mImpl; public: explicit constexpr WrappedVirtualAllocator(TImpl impl = {}) MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v) : mImpl(std::move(impl)) {} constexpr WrappedVirtualAllocator(const WrappedVirtualAllocator&) = default; constexpr WrappedVirtualAllocator(WrappedVirtualAllocator&&) = default; WrappedVirtualAllocator& operator=(const WrappedVirtualAllocator&) = default; WrappedVirtualAllocator& operator=(WrappedVirtualAllocator&&) = default; [[nodiscard]] owner_t allocate(std::size_t count) noexcept override { return mImpl.allocate(count); } void deallocate(owner_t ptr, std::size_t count) noexcept override { mImpl.deallocate(ptr, count); } }; template WrappedVirtualAllocator makeVirtualAllocator(T allocator) MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v) { return WrappedVirtualAllocator(std::move(allocator)); } } // namespace mijin #endif // !defined(MIJIN_MEMORY_VIRTUAL_ALLOCATOR_HPP_INCLUDED)