Lazy range of hashes?

Artur Skawina art.08.09 at gmail.com
Sun Aug 26 09:54:33 PDT 2012


On 08/26/12 17:28, Ali Çehreli wrote:
> On 08/26/2012 12:55 AM, Era Scarecrow wrote:
>> On Sunday, 26 August 2012 at 07:29:13 UTC, Ali Çehreli wrote:
>>> Cool! :) If the operator returns the pointer to the element, then the
>>> callers can access its value as well
>>
>> Reminds me, although not for you Ali, but as a pointer return a question
>> came up. I've wondered and haven't tested this but hypothetically:
>>
>> Due to that you can call structures and class members even from a
>> pointer (transparently compared to C/C++),
> 
> It has been argued that the -> operator has not been needed for C anyway.
> 
> Interestingly, it has some value in C++ because if a type has defined operator->() (rather, for this discussion, operator.(), which does not exist in C++ today), then the following would cause confusion for types that worked like smart pointers:
> 
> class P
> {
>     /* hypothetical operator */
>     T * operator.();
>     void foo();
> };
> 
>     P p = bar();
>     p.foo(); // foo() of the pointer type or the 'pointed to type'?
> 
> D does not have that question because the dot operator may not be overloaded. (opDot() has been (will be?) deprecated.)

opDispatch lets you write the equivalent in D [1]. The 'local' member always has
to take precedence over any 'remote' ones (you can hide (rename/wrap etc) the
local one if you want, doing it the other way wont work).

>> does it automatically convert
>> from a pointer to a non-pointer type if the return calls for it?
> 
> No: The dot does not convert the type. The dot has different meanings on structs vs. classes. With structs, it always operates on the struct object:
> 
>     o.sizeof   // The size of the struct object
>     o.foo()    // The member of the struct object
> 
> With classes, it operates sometimes on the reference and sometimes on the referenced object:
> 
>     o.sizeof   // The size of the class reference
>     o.foo()    // The member of the class object
> 
> That's D's way of confusing on this topic.

The dot means the same thing, you just have to remember that a class reference is
actually a pointer to the class instance. IOW 'o.whatever' for classes works just
like 'p.whatever' does for structs.

What is confusing is the wrong reference_type-to-pointer model, but fixing it up
right now is too late. Or maybe not, given the tiny amount of D code out there and
the fact that only code dealing with pointers-to-classes would be affected. Such
code is probably so rare that the cost could still be acceptable.

artur

[1] Well, almost - there are things like dealing with '@property' which need
    improvements. And of course 'alias this' can be used, sometimes.


More information about the Digitalmars-d-learn mailing list