Re:More Dirty Coding Tricks from Game Developers (2010)
by danielweber on Sunday August 02, 2015 @06:49PM
(#9992809)
Absolutely nothing there was surprising. The worst thing is that if a library uses const, you have to use it too.
[ Parent
| on HN ]
Re:More Dirty Coding Tricks from Game Developers (2010)
by cmma on Sunday August 02, 2015 @10:19PM
(#9993365)
Explain?
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.
Re:More Dirty Coding Tricks from Game Developers (2010)
by CountSessine on Sunday August 02, 2015 @08:00PM
(#9993032)
That 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.