Skip to content

Process/scheduler fails to compile when using std::pmr::polymorphic_allocator #1302

Description

@coldcola233

EnTT version: 3.16.0

#include <entt/entt.hpp>
#include <memory_resource>

template<class Delta, class Allocator>
struct MyProcess : entt::basic_process<Delta, Allocator> {
    using process_type = entt::basic_process<Delta, Allocator>;
    using allocator_type = typename process_type::allocator_type;
    using delta_type   = typename process_type::delta_type;

    MyProcess(const allocator_type &alloc, delta_type delay)
        : process_type{alloc}, remaining{delay} {}

    void update(delta_type d, void*) override {
        remaining -= d;
        if (remaining <= delta_type{0}) this->succeed();
    }
private:
    delta_type remaining;
};

using Sched = entt::basic_scheduler<float, std::pmr::polymorphic_allocator<void>>;
using Proc  = MyProcess<float, std::pmr::polymorphic_allocator<void>>;

int main() {
    std::pmr::unsynchronized_pool_resource pool;
    std::pmr::polymorphic_allocator<void> alloc{&pool};
    Sched sched{alloc};
    sched.attach<Proc>(1.0f);   // <-- error here
}

The method attach is implemented as:

    template<typename Type, typename... Args>
    type &attach(Args &&...args) {
        const auto &allocator = handlers.second();
        return *handlers.first().emplace_back(std::allocate_shared<Type>(allocator, allocator, std::forward<Args>(args)...));
    }

MyProcess satisfies std::uses_allocator_v, so std::allocate_shared will attempt to propagate std::pmr::polymorphic_allocator<void>.
But it failed.

Metadata

Metadata

Assignees

Labels

enhancementaccepted requests, sooner or later I'll do it

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions