The destructors are not called, so I would fear resource leak.
If you don't know what a code does, then don't write such a code.
If you receive such a code, change it to have a valid code that you do know what it does.
So how would you ensure that the destrcutors are always called? The only thing I can think of is a Chunk class template (that's like a pointer wrapper) that stores a pointer to the memory pool it belongs to. And upon destruction of a Chunk object, it can call a member function of a MemoryPool object to call the appropiate destructor.
Would this be too complex? I don't want to depend on the user to manually clean up resources.
I was going to try writing a really basic memory pool class just for practice, but I didn't realize it would already be tricky.
This will cause undefined behaviour if bazptr is not aligned on std::alignment_of<BAZ>::value
This may (probably will) result in resource leaks if std::is_trivially_destructible<FOO>::value is false
or std::is_trivially_destructible<BAR>::value is false
> So how would you ensure that the destrcutors are always called?
Oh, I'm still new to placement new, so I didn't know you could use it with smart pointers. You have enlightened me very much. Now I understand better what those extra parameters in the smart pointer constructors are for.
I've never had to deal with alignment, so this will be an extra challenge for me.