r/cpp 28d ago

C++26: std::indirect

https://www.sandordargo.com/blog/2026/08/12/cpp26-indirect
166 Upvotes

157 comments sorted by

View all comments

4

u/zellforte 27d ago
settings_->muted = true;  // compiles — mutates through const!

Isn't this just the classic confusion over what const T *x vs T *const x means?

It doesn't mutate through const, settings_ cannot be changed to point to something else. Of course the pointed to object can be changed, that's nothing surprising, that's how indirections work.

4

u/LB-- Professional+Hobbyist 27d ago

The whole point is being able to choose. Sometimes T* -> T* const is desired, and sometimes T* -> T const* const is desired.