pure functions/methods

Sean Cavanaugh WorksOnMyMachine at gmail.com
Fri Apr 20 01:15:49 PDT 2012


On 4/20/2012 3:06 AM, Namespace wrote:
> The sense of pure functions isn't clear to me.
> What is the advantage of pure functions / methods?
> I inform the compiler with "const" that this method does not change the
> current object, and therefore he can optimize (at least in C++) this
> method. How and what optimized the compiler if i have "pure" or "const
> pure" functions / methods?

Simplest explanation I can think of is:

a const function of a class can't modify its own classes data
a pure function can't modify any data, or call other functions that are 
not also pure (though there are exceptions)



More information about the Digitalmars-d-learn mailing list