Why Strings as Classes?
Denis Koroskin
2korden at gmail.com
Tue Aug 26 13:04:26 PDT 2008
On Tue, 26 Aug 2008 23:58:10 +0400, Denis Koroskin <2korden at gmail.com>
wrote:
> On Tue, 26 Aug 2008 23:29:33 +0400, superdan <super at dan.org> wrote:
> [snip]
>>> The D spec certainly doesn't make any guarantees about
>>> the time/memory complexity of opIndex; it's up to the implementing
>>> class
>>> to do so.
>>
>> it don't indeed. it should. that's a problem with the spec.
>>
>
> I agree. You can't rely on function invokation, i.e. the following might
> be slow as death:
>
> auto n = collection.at(i);
> auto len = collection.length();
>
> but index operations and properties getters should be real-time and have
> O(1) complexity by design.
>
> auto n = collection[i];
> auto len = collection.length;
The same goes to assignment, casts, comparisons, shifts, i.e. everything
that doesn't have a function invokation syntax.
BTW, that's one of the main C++ criticisms: you can't say how much time a
given line may take. It is predictable in C because it lacks operator
overloading.
More information about the Digitalmars-d
mailing list