First experience with std.algorithm: I had to resort to writinga
Jonathan M Davis
jmdavisProg at gmail.com
Tue Jun 8 12:19:38 PDT 2010
Andrei Alexandrescu wrote:
> On 06/08/2010 06:59 AM, bearophile wrote:
>> Bernard Helyer:
>>> bool contains(T)(const(T)[] l, T a)
>>> {
>>> foreach(e; l) {
>>> if (a == e) {
>>> return true;
>>> }
>>> }
>>> return false;
>>> }
>>
>> See also:
>> http://d.puremagic.com/issues/show_bug.cgi?id=3923
>
> That issue stems from the fact that find is quite flexible. I agree it
> has lost modularity in the process. I'll work on restoring its modularity.
>
> Andrei
The biggest issue is the documentation rather than the function, I think. If
find() can be broken up, that could help, but the main issue is what the
documentation looks like. It's just too complicated - especially the
function signature. Pretty much the only sane way to figure the
std.algorithm functions out is to focus on the examples (which while good
are still fairly sparse). As it stands, I expect the documentation to scare
away potential users of std.algorithm. It looks far scarier than it actually
is. We need to find a way or ways to make the documentation simple like the
functions are simple to use (since, for the most part they're pretty easy to
use in spite of their nasty signatures).
As for a contains() function, I would argue that it would be nice to add one
regardless of the state of find(). Not only would it would make its usage
clearer in the use case where you're checking whether a range contains a
value, but it could almost certainly be better optimized for such a use case
- if nothing else because it wouldn't have to construct a range, just return
a bool.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list