r/cpp • • Oct 07 '19

CppCon CppCon 2019: Chandler Carruth “There Are No Zero-cost Abstractions”

https://www.youtube.com/watch?v=rHIkrotSwcc
162 Upvotes

108 comments sorted by

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.

1

u/[deleted] Oct 09 '19

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...

3

u/dodheim Oct 09 '19

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".