pure vs std.range.retro

John Carter john.carter at taitradio.com
Sun Dec 22 14:37:43 PST 2013


Thanks for all your help understanding the algorithm chaining problem...

Now I have another gotcha.

This code compiles and runs OK if I remove the keyword "pure" or if I
remove the ".retro"

As I understand it retro should affect the "pure"ness of the the function.

If I put the keyword in, it fails to instantiate the template...
import std.algorithm;
import std.array;
import std.stdio;
import std.range;

pure auto huh( in uint[] digitArray, in uint value)
{
   return find!( (a,b) => (a > b))( digitArray.retro, value);
}

unittest {
   auto test = [11u, 1u, 1u, 10u];
   auto s = huh( test, 10u);
   writeln( s);
}

dmd -unittest -main  doesnt_work.d && ./doesnt_work
/usr/include/dmd/phobos/std/algorithm.d(3508): Error: pure function
'doesnt_work.huh' cannot call impure function
'std.range.retro!(const(uint)[]).retro.Result.popFront'
/usr/include/dmd/phobos/std/algorithm.d(3510): Error: pure function
'doesnt_work.huh' cannot call impure function
'std.range.retro!(const(uint)[]).retro.Result.front'
doesnt_work.d(8): Error: template instance doesnt_work.huh.find!(__lambda3,
Result, const(uint)) error instantiating

-- 
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand

-- 

------------------------------
This email, including any attachments, is only for the intended recipient. 
It is subject to copyright, is confidential and may be the subject of legal 
or other privilege, none of which is waived or lost by reason of this 
transmission.
If you are not an intended recipient, you may not use, disseminate, 
distribute or reproduce such email, any attachments, or any part thereof. 
If you have received a message in error, please notify the sender 
immediately and erase all copies of the message and any attachments.
Unfortunately, we cannot warrant that the email has not been altered or 
corrupted during transmission nor can we guarantee that any email or any 
attachments are free from computer viruses or other conditions which may 
damage or interfere with recipient data, hardware or software. The 
recipient relies upon its own procedures and assumes all risk of use and of 
opening any attachments.
------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20131223/458f87a3/attachment.html>


More information about the Digitalmars-d-learn mailing list