From 6dede936bd39a6632387726a97c615198184d88a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 1 Oct 2018 15:35:06 +1000 Subject: [PATCH] alloc/arena: Add an arena that contains an allocator. --- alloc/arena.hpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) 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