object oriented value type
BCS
ao at pathlink.com
Mon Jun 25 12:10:54 PDT 2007
Reply to Robert,
> I do think having a syntax to add properties to primitive types is a
> good idea, though, in the same way as the funky array syntax works
> now.
how about
|typedef int myInt
|{
| static addCount=0; // static members? why not?
|
| myInt opAdd(myInt that)
| {
| addCount++;
| return this+that; // this is int
| }
| private opMod(); // forbid mod on myInt
|}
added in template typedefs:
|typedef real SIuint(int dist, int mass, int time)
|{
| SIuint!(dist+T.dist, mass+T.mass, time+T.time) opMull(T)(T p) // in-lining
reduces to same as normal mul
| {
| return this*p;
| }
|}
and some really cool stuff starts happening
More information about the Digitalmars-d
mailing list