News for hackers. Stuff that matters.
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.

There are no comments on this comment yet.