On 03/14/2016 08:12 PM, Glen Fernandes wrote:
Comment out what from where? More simply, if someone wants to use root_ptr with a conforming C++ allocator (such as Allocator<T> in that example) what must they do?
e.g. With shared_ptr they would use allocate_shared: shared_ptr<int> p1 = allocate_shared<int>(Allocator<int>(state));
e.g. With vector they would just use the constructor: vector
v1(Allocator<int>(state)); e.g. With function they would just use the constructor: function
f1(allocator_arg, Allocator<void>(state)); From the code that you showed, it looks like for block_ptr, they would need to do: nodealloc<int>::PoolType a1(state); root_ptr<int> p1 = new(a1) nodealloc<int>(a1);
But first they need to define the nodealloc class template?! That doesn't seem right.
No I just scribbled something quickly but I need to clean up node_base.hpp and make nodealloc<> generic.
What happens if they want to pass constructor parameters as well?
struct T { T(int, char, bool) { } }; auto p1 = std::allocate_shared<T>(Allocator<T>(state), 5, 'g', false);
How would they do that with root_ptr? Would they have to define a new nodealloc class template to do it?
No like I was saying nodealloc<> could be used for other instantiated allocators as well. And I could well easily define function wrappers as well to something like "std::allocate_node<>" but ideally I would prefer not to because I find it redundant if the placement operator new works correctly.