Restrict Class Properties?

Jarrett Billingsley kb3ctd2 at yahoo.com
Fri Feb 23 16:48:27 PST 2007


"Manfred Nowak" <svv1999 at hotmail.com> wrote in message 
news:erns67$2d2$1 at digitalmars.com...
>
> I do not see the general usability if such would be enabled. Under
> which circumstances are untemplated classes useful, that contain
> templated functions?
>

I've found templated member functions immensely useful for doing things with 
variant-like types, though I encounter that a lot only because I'm writing a 
dynamically-typed scripting language.  Additionally, I use tuples for 
variadic functions because there are some things which would just be too 
ugly/slow with normal variadic functions.  I have a ".call" method in my 
interpreter class that I can just pass a tuple of arguments, and it'll 
automatically convert them to variant types and push them onto the 
interpreter stack, and it does that in about six lines of code.  Other uses 
would include maybe an IO class that has to be able to write or read any 
kind of data.  Much easier to do so with a templated member function than 
with a million overloads (I'm looking at _you_, std.stream).

> For a class C one has to define an inner class I that implements the
> required op=, ++, and -- operators; has to declare within Class C
> the property as approximately "I property;"; has to extend the
> constructor of Class C by a "property= new I;".
>
> Then one can code:
>  auto c= new C;
>  c.property <op>= ...

Oh, I see.  Yeah, that is possible.  You could even do it with an inner 
struct, too.  Would be lighter weight.

> The specs
> | Note: Properties currently cannot be the lvalue of an op=, ++, or
> | -- operator.
> do not hold for class properties.

It holds for _typical_ class properties, i.e. implicit function calls.  But 
you're right, they can be made to _look_ like they're working correctly with 
a workaround. 





More information about the Digitalmars-d mailing list