Struct allocation_deleter

Synopsis

#include <src/entt/core/memory.hpp>

template<typename Allocator>
struct allocation_deleter: private Allocator

Description

Deleter for allocator-aware unique pointers (waiting for C++20).

Template Parameters

Args - Types of arguments to use to construct the object.

Mentioned in

Inheritance

Ancestors: Allocator

Methods

allocation_deleterInherited constructors.
operator()Destroys the pointed object and deallocates its memory.

Source

Lines 111-134 in src/entt/core/memory.hpp.

template<typename Allocator>
struct allocation_deleter: private Allocator {
    /*! @brief Allocator type. */
    using allocator_type = Allocator;
    /*! @brief Pointer type. */
    using pointer = typename std::allocator_traits<Allocator>::pointer;

    /**
     * @brief Inherited constructors.
     * @param alloc The allocator to use.
     */
    allocation_deleter(const allocator_type &alloc)
        : Allocator{alloc} {}

    /**
     * @brief Destroys the pointed object and deallocates its memory.
     * @param ptr A valid pointer to an object of the given type.
     */
    void operator()(pointer ptr) {
        using alloc_traits = typename std::allocator_traits<Allocator>;
        alloc_traits::destroy(*this, to_address(ptr));
        alloc_traits::deallocate(*this, ptr, 1u);
    }
};





Add Discussion

Log in to comment