On Sunday, 28 June 2015 at 15:55:51 UTC, jmh530 wrote:
My understanding of pure is that a function labeled pure can
only include pure functions. I've been confused by the fact
that a function calling map (like below) can be labeled pure
without any problems. The only way I can rationalize it is that
map really isn't a function, it's (if I'm understanding it
correctly) a template that creates a template function that
calls a struct template.
auto test_map(T)(T x) pure
{
return x.map!(a => a + a);
}
This is related to
http://forum.dlang.org/thread/[email protected]?page=1
but maybe my question is more basic.
Map isn't explicitly marked as pure. D can infer purity for
templated functions, so as long as you give it a pure predicate,
map can be inferred as pure. This only works for templated
functions; non-templated functions must be explicitly marked as
pure.