Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

“the count() member function sounds like it should be non-modifying, but in fact it needs to update member data and thus cannot be const”

That isn’t correct. Just declare count as mutable. See https://en.cppreference.com/w/cpp/language/cv. Memoization is a valid use case for that feature.



Often it's the motivating example when the feature gets explained.


I would argue that mutexs or other concurrency primitives are the quintessential example, but caching is the other big one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: