pointers, functions, and uniform call syntax

Jonathan M Davis jmdavisProg at gmx.com
Mon Sep 3 14:44:31 PDT 2012


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


More information about the Digitalmars-d mailing list