`std::future::then` 会分配内存吗?可以自定义分配器吗?

Mai*_*kel 5 c++ future executor

std::promise有一个构造函数,它分配用于存储共享状态的内存。.then在我到目前为止所看到的 的实现中,人们以类似于共享状态std::function 的类型擦除方式存储函数。stlab 的并发库甚至放置了一个

using then_t = std::vector<std::pair<executor_t, task<void()>>>;
Run Code Online (Sandbox Code Playgroud)

进入共享状态(以启用可拆分的 future)。

是否有意指定是否可以为延续指定分配器?

P0443R3中,他们在 1.2.9 自定义内存分配的属性中说

执行器实现应使用提供的分配器来分配存储提交的函数对象所需的任何内存。

我认为这仅意味着通过函数提交的代理的存储,而不是共享状态中的execute指针。 std::future

我研究了最近关于期货或执行人的提案,但我找不到任何东西。无论如何,最近的论文似乎倾向于让执行者处于共同的未来状态。如果执行器有一个关联的自定义分配器,是否应该使用它?

我感觉我错过了什么。

--

编辑:我对此进行了更多思考,我想我可以理解为什么有人愿意不明确这一点。如果 future 由执行者参数化,那么它们的共享状态可能如下所示

template <typename Executor, typename T>
struct shared_state_t {
    // some prevention from race condition, for example
    std::atomic<unsigned> flags;
    // some sort of exception or value representation, for example
    std::variant<std::exception_ptr, T> maybe_value;
    // some handle to continuation
    continuation_t<Executor, T> continuation;
};
Run Code Online (Sandbox Code Playgroud)

wherecontinuation_t<Executor, T>不需要分配内存。它可以是指向一个执行器的内部执行代理的指针,也可以是另一个执行器的Executor类似指针。std::function<void(T&&)>