We need a way to make functions pure and/or nothrow based on the
"Jérôme M. Berger"
jeberger at free.fr
Sun Nov 14 04:49:54 PST 2010
bearophile wrote:
>> @optional_tag(isPure!F, pure) int[] map(F)(F f, int[] data) {
>> int[] res;
>> foreach (x; data)
>> res ~= f(x);
>> return res;
>> }
>
> This may not suffice to correctly tell apart strong pure functions from weak pure ones...
>
Untested:
==============================8<------------------------------
template optionalTag (bool test, char[] tag) {
static if (test)
const char[] optionalTag = tag;
else
const char[] optionalTag = "";
}
template bool isPure(F)() {
return functionAttributes!F & FunctionAttribute.PURE;
}
mixin(optionalTag!(isPure!F, "pure")) int[] map(F)(F f, int[] data) ...
------------------------------>8==============================
Of course, this suffers from the ugly syntax for string mixins...
Jerome
--
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101114/4c73b188/attachment.pgp>
More information about the Digitalmars-d
mailing list