Theres also the `const` on the function itself. If I do:
struct Foo {
int GetVal() const {
return Val;
}
int Val
};
void Bar(const Foo& f){
int val1 = f.GetVal();
int val2 = f.GetVal();
assert(val1 == val2);
}
This is not guaranteed for a variety of reasons. This means that there are many optimisations that are just unavailable because of const, and there are guarantees that on first glance you expect to be true, but arent.
I understand why, we don't need to go into it, but its a mess that const doesn't actually mean constant.
It just means you've opted into coloured functions [0]. It's not quite as painful as async functions in js, but all the same arguments apply.
Theres also the `const` on the function itself. If I do:
This is not guaranteed for a variety of reasons. This means that there are many optimisations that are just unavailable because of const, and there are guarantees that on first glance you expect to be true, but arent.I understand why, we don't need to go into it, but its a mess that const doesn't actually mean constant.
It just means you've opted into coloured functions [0]. It's not quite as painful as async functions in js, but all the same arguments apply.
[0] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-... t