First experience with std.algorithm: I had to resort to writing a 'contains' function.

Alex Makhotin alex at bitprox.com
Tue Jun 8 06:31:46 PDT 2010


Bernard Helyer wrote:
> 
> This worked. Until I turned unittests on, and the assert I showed above 
> tripped. At this point my language turned rather unpleasant and I wrote 
> this:
> 
> bool contains(T)(const(T)[] l, T a)
> {
>      foreach(e; l) {
>          if (a == e) {
>             return true;
>          }
>      }
>      return false;
> }
> 
> And my problems went away. I assume what I experienced is a bug, but I'm 
> not sure, so I thought I'd share my experience.

I want you to know that you are not the only one who makes such 
decisions. I have almost the same method, except it returns an index 
value. That is not the only one reason I wanted a std library with clear 
and documented interfaces. Generally I use std library to make writeln, 
thread wrapper around OS, and string conversions. I do not want to use 
std.algorithm.


-- 
Alex Makhotin,
the founder of BITPROX,
http://bitprox.com


More information about the Digitalmars-d mailing list