What features of D are you using now which you thought you'd never goint to use?
Dmitry Olshansky
dmitry.olsh at gmail.com
Sun Jun 23 07:46:09 PDT 2013
23-Jun-2013 06:13, Brad Anderson пишет:
> On Sunday, 23 June 2013 at 01:34:53 UTC, Andrei Alexandrescu wrote:
>> On 6/22/13 2:58 PM, monarch_dodra wrote:
>>> long story short: we don't have rfind. C++ does.
>>
>> We do, just that it's for random-access ranges. C++ offers it for
>> bidirectional ranges too. We could of course support it if
>> bidirectional ranges were required to have something like
>> r1.before(r2) that, assuming r2 is reachable from r1, returns the
>> portion in r1 that's before r2.
>>
>> Andrei
>
> That sounds like exactly what I needed for a version of toUpper I was
> playing with that added support for output ranges.
>
> The implementation is rather trivial:
>
> Writer toUpper(S, Writer)(S s, Writer w) @trusted
And I would love to add functions of this style to the new std.uni
especially as toLower is a fair bit more tricky then this.
> if(isSomeString!S)
> {
> size_t count = 0;
> foreach (c, i; s)
> {
> if (std.uni.isLower(c))
> {
> c = std.uni.toUpper(c);
> }
> put(w, c);
> count = i;
> }
>
> return w;
> }
>
> Works just fine with something like Appender. The problem is that if you
> pass in dynamic or static array slice to store the result in you have no
> way of knowing how much of the target array was filled by the function.
> You could use save() and keep track of how many bytes were consumed and
> return a slice of that size but that feels very clunky (and could be
> tricky to implement correctly if the input string is a different
> encoding than the output range).
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list