property syntax strawman

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Sun Aug 2 02:00:38 PDT 2009


Walter Bright wrote:

>    bool empty { ... }
>    void empty=(bool b) { ... }
> 
> The only problem is when a declaration but not definition is desired:
> 
>    bool empty;
> 
> but oops! That defines a field. So we came up with essentially a hack:
> 
>    bool empty{}
> 
> i.e. the {} means the getter is declared, but defined elsewhere.
> 
> What do you think?

It is quite hack-ish. There are ways to have your cake and eat it too. I
wouldn't settle for 'bool empty{}'.

--------------------------------------------------
bool empty {
    void set(auto value) { ... }
    auto get() { ... }
}

empty = false; // empty.set(false)
auto b = empty; // auto b = empty.get()
--------------------------------------------------

for example, requires no hacks and no keywords. And has the added advantage
that you can still use the getter and setter methods directly. To call them
or get delegates from them.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list