3 ms·
Absolutely nothing there was surprising. The worst thing is that if a library uses const, you have to use it too.
by danielweber 11y ago
Absolutely nothing there was surprising. The worst thing is that if a library uses const, you have to use it too.
- CountSessine 11y agoThat library might have been coded assuming invariance and a mutable implementation might not have been possible with the same time/space behaviour. If I wrote a library and made something const, I did that for a reason. I didn't do that just to piss you off.
- cmma 11y agoExplain? The most common usage of const in library code is for function parameters: Iterator find(T const& value) const; The const actually _helps_ callers: find accepts both const and non-const references. A non-const argument will be implicitly cast to const by the compiler. Compare that to: Iterator find(T& value) const; This function signature accepts only non-const references (unless T is const). A caller must const_cast a const argument to use it (bad). Return values are occasionally references: T& front(); T const& front() const; But "auto" makes the code shorter when the return type is const or unknown: auto& v = c.front(); // overload is deduced by the compiler based on the constness of c.