Why Strings as Classes?

bearophile bearophileHUGS at lycos.com
Wed Aug 27 10:23:53 PDT 2008


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



More information about the Digitalmars-d mailing list