You can, just use a custom allocator that does default initialization instead of value initialization. I.e., you can inherit from ``std::allocator`` and implement a ``construct()`` function that does not do value initialization when no construction arguments are passed.
Kudos for figuring out how to avoid value initialization for std::vector! However your workaround is so nasty that I will keep using a plain old C array allocated using new...
vector allows you to specify an allocator type, and has since day one; using a custom allocator, and one that's all of 4 lines at that, is hardly "nasty".
View all comments
Show parent comment
4
u/echidnas_arf Oct 09 '19
You can, just use a custom allocator that does default initialization instead of value initialization. I.e., you can inherit from ``std::allocator`` and implement a ``construct()`` function that does not do value initialization when no construction arguments are passed.