Why Strings as Classes?
Denis Koroskin
2korden at gmail.com
Wed Aug 27 10:31:16 PDT 2008
On Wed, 27 Aug 2008 21:23:53 +0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> Robert Fraser:
>> It's a good feature to have (I wouldn't consider a list class complete
>> without it), it just shouldn't be abused.
>
> Its code:
>
> final Ref nth (int n) {
> auto p = this;
> for (int i; i < n; ++i)
> p = p.next;
> return p;
> }
>
> If the usage patterns show this is positive, then a static pointer/index
> pair may be added, that keeps the last accessed pointer/index, this may
> speed up things if the items are accessed sequentially, or even if they
> are accessed with some several forward skips, avoiding starting from the
> beginning each time :-)
>
> Bye,
> bearophile
I believe this breaks encapsulation, unless an iterator is returned and
passed as a start. Find is a better name for such operation.
More information about the Digitalmars-d
mailing list