mirror of
https://github.com/allankoechke/KDToolBox.git
synced 2026-11-30 10:18:42 +00:00
For individual files: use year of file creation For entire project: remove year from the statement use the © where feasible reference: https://matija.suklje.name/how-and-why-to-properly-write-copyright-statements-in-your-code
propagate_const
**
A minimal reimplementation of std::experimental_::propagate_const from
the C++ Extensions for Library Fundamentals version 3.
**
The propagate_const class is a deep-const wrapper for pointers and smart pointers. If you have a class and want to ensure const correctness even for its data members that are held by (smart) pointer, wrap them in a propagate_const:
class MyClass {
KDToolBox::propagate_const<Data *> m_data;
public:
void observer() const {
m_data->mutate(); // ERROR
}
};
"Ordinary" pointers (raw and smart) do not deeply propagate const, and
would let the user accidentally (or deliberately) mutate m_data above.
If the state of m_data logically belongs to the observable state of
*this, then the ordinary (smart) pointer would violate const
correctness. The usage of propagate_const prevents that mistake from
happening.
Requires a C++17 capable compiler.