std.string and std.algorithm: what to do?

Georg Wrede georg.wrede at iki.fi
Fri May 15 18:36:29 PDT 2009


Derek Parnell wrote:
> On Thu, 14 May 2009 17:33:40 -0400, Steven Schveighoffer wrote:
> 
>> On Thu, 14 May 2009 17:21:02 -0400, Derek Parnell <derek at psych.ward> wrote:
>  
>> Not really.  What could funcA possibly do with the index without the  
>> string itself?  If it's just a flag (uint.max or not), then funcA should  
>> be:
>>
>> funcA(bool found, ...)
>>
>> and you call it with
>>
>> funcA(find(needle, haystack) < haystack.length, xyzzy)
>>
>> This doesn't cause any problems with people who use Tango, which returns  
>> the length if not found.  In other words, if you find yourself writing  
>> code to "morph" the length into uint.max or -1, you are thinking about the  
>> problem incorrectly.
> 
> Who said that I had control of how funcA() was implemented?

Well, if you wrote

   funcA(find(needle, haystack) < haystack.length, xyzzy)

then it is you, who decided to use funcA. Now, if that wasn't to your 
liking, you'd of course write your own funcA (or use another function), 
that works as you want.

Therefore, you're "in control of funcA() here".



More information about the Digitalmars-d mailing list