I have seen sometimes people use a generic void allocator defined like this :
using namespace boost::interprocess;
typedef allocator<void, managed_shared_memory::segment_manager> VoidAllocator;
Is it considered a bad practice ? I found that std::allocator is depreciated, should I be concerned about the boost version ?
I don't think it is bad practice, but mostly a useless practice.
An allocator
of void
cannot allocate anything and doesn't have any useful trait.
So at the end it is only useful for rebinding.
And if you are rebinding, you can actually replace void
by char
anyway.
Maybe there is a "symmetry" argument to have a void
allocator, but it creates confusion since there are not reference
, size_type
or other typical trait members.
(The idea of rebinding allocators is odd in the first place, probably a remnant of old language limitations. Allocators shouldn't need to know the type they are allocating, because is at best redundant and at worst the container usually rebinds to the type it really needs anyway --e.g. node types--.)