Ok, thank you for the example. In this case you can't tell C++ it won't change. The best way is to change your code, so it won't use globals. And if it's member function, you should mark it const.
And const [references] doesn't do much for my cases (see upthread). I agree that assume seems like a poor fit, it seems more like a type system level issue. But I'd take anything :)
-
-
I think I understand where you're coming from, but assumptions are not for that. Assumptions are for local things. They are there to trigger certain optimisations in a certain line of code, not to reason about functions across different TUs. I think you need another feature.
-
If you want to be sure a func won't change an object, keep a copy, or make sure the obj itself is const in the context of that func. If the compiler can't see inside the func, & the func can access the obj through a non-const reference, there is no way of knowing it won't change.
- 5 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.