#ifndef SOPHIAR2_SMALL_OBJ_H #define SOPHIAR2_SMALL_OBJ_H #include #include #include #include #include namespace sophiar { template struct small_obj_ref_counter : private boost::noncopyable { uint32_t ref_count = 0; }; template void intrusive_ptr_add_ref(small_obj_ref_counter *pointer) { ++pointer->ref_count; } template void intrusive_ptr_release(small_obj_ref_counter *pointer) { if (--pointer->ref_count == 0) { DeriveT::allocator.destroy(static_cast(pointer)); } } template struct small_obj : public small_obj_ref_counter { using pointer = boost::intrusive_ptr; using allocator_type = boost::object_pool; // static allocator_type allocator; inline static allocator_type allocator; template std::enable_if_t, pointer> static new_instance(Args &&... args) { auto ret_pointer = allocator.malloc(); std::construct_at(ret_pointer, std::forward(args)...); return ret_pointer; } }; // template // typename small_obj::allocator_type small_obj::allocator{}; #define FORWARD_CONSTRUCT(DerivedT, BaseT) \ template \ explicit DerivedT(Args &&...args) \ :BaseT(std::forward(args)...) { \ static_assert(std::is_constructible_v); \ } } #endif //SOPHIAR2_SMALL_OBJ_H