diff --git a/alloc/arena.hpp b/alloc/arena.hpp index d2bb8bdf..15a58f1d 100644 --- a/alloc/arena.hpp +++ b/alloc/arena.hpp @@ -79,6 +79,43 @@ namespace cruft::alloc { private: T &m_store; }; -} + + + /// A simple allocator that contains a raw allocator and a forwarded + /// allocator. + /// + /// The raw allocator handles the memory allocation, the forwarded + /// allocator performs the initialisation, and we control the construction + /// of both. + /// + /// Ideally we wouldn't forward calls manually and instead do something + /// like inherit from arena, but that makes it difficult to initialise + /// the raw allocator before we have to supply the reference to the arena. + template + class owned { + public: + template + owned (ArgsT &&...args): + m_store (std::forward (args)...), + m_arena {m_store} + { ; } + + template + decltype(auto) acquire (ArgsT &&...args) + { return m_arena.template acquire (std::forward (args)...); } + + template + decltype(auto) release (ArgsT &&...args) + { return m_arena.release (std::forward (args)...); } + + template + decltype(auto) unique (ArgsT &&...args) + { return m_arena.template unique (std::forward (args)...); } + + private: + AllocT m_store; + arena m_arena; + }; +}; #endif