Will you use it?
See My Talk: Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
by Bartlomiej Filipek
Summary of the talk:
Sometime in 2016, I wrote an article about custom deleters for smart pointers.
Bartek’s coding blog: Custom Deleters for C++ Smart Pointers
And there is an interesting property that if you have a unique_ptr and you provide a stateless functor, then the size of unique_ptr is just one pointer (not two when you use a function pointer). But at that time, I didn’t investigate what the exact reason behind this capability was.
Then in February 2020, I gave a presentation on our C++ User Group about all of the C++20 features. And among them, there’s a new attribute called [[no_unique_address]]. At that time, I also had no clear idea of what were the use cases for it.
But then I wanted to understand more of C++20 and somehow those two features: deleters for unique_ptr and [[no_unique_address]] started to “converge”.
As it appears with the new attribute from C++20, we can significantly simplify the code that leverages Empty Base Class Optimisation to create things like “compressed pairs” often used to store stateless callable objects like allocators or deleters.
Add a Comment
Comments are closed.