pointers, functions, and uniform call syntax

Carl Sturtivant sturtivant at gmail.com
Mon Sep 3 15:21:53 PDT 2012


On Monday, 3 September 2012 at 21:44:15 UTC, Jonathan M Davis
wrote:
> On Monday, September 03, 2012 23:19:07 Carl Sturtivant wrote:
>> So I'm wondering if a language extension along the following
>> lines would solve your problem,
>
> Whoa. Stop right there. Language extension? If you think that 
> you need a
> language extension to solve a problem, odds are that you're 
> going about things
> the wrong way. Sometimes a language extension would indeed be 
> needed to do
> something, but odds are, it's not. D is a very powerful 
> language. Think long
> and hard about how to do something _within_ the language before 
> you even
> consider extending it.
>
> If all you're looking to do is make it so that you don't have 
> to care whether
> you're dealing with an S or S*, then a language extension is 
> complete
> overkill. Just make a wrapper struct. Something like (untested):
>
> struct Wrapper(T)
> {
>     T* ptr;
>
>     ref inout(T) get() inout { return *ptr; }
>
>     alias get this;
> }
>
> Just wrap an S* in that, and you can use it exactly as if it 
> were an S.
> Problem solved.
>
> - Jonathan M Davis

---same thing (specialized to struct S) in my first reply.
I'm just fishing, seeking a boundary.

There is a cleanness issue to discuss. It would be nice to know
what you think about implicit conversion from 'S*' to 'ref S'
(and not the other way as someone seemed to be suggesting). It's
hard for a newish outsider to get a sense of where the boundaries
lie.




More information about the Digitalmars-d mailing list