object oriented value type
Henning Hasemann
hhasemann at web.de
Mon Jun 25 14:41:08 PDT 2007
BCS <ao at pathlink.com> schrieb (Mon, 25 Jun 2007 19:10:54 +0000 (UTC)):
> 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.
Wouldnt it be more straigtforward if there were no basic types at all?
Ok, you then run into the OO-value-type question again, but somithing
like (to follow the example below)
// No special syntax needed to declare that this is a value type as it
// inherits from one (int)
class MyInt : int {
static addCount = 0;
MyInt opAdd(MyInt that) {
addCount++;
return this.value + that.value;
}
}
> how about
>
> |typedef int myInt
> |{
> | static addCount=0; // static members? why not?
> |
> | myInt opAdd(myInt that)
> | {
> | addCount++;
> | return this+that; // this is int
That would be a bit confusing at it looks like recursion.
> | }
> | 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;
> | }
> |}
I must confess I dont think that I understand your example. Would that
allow multiplying integers with units?
Henning
--
GPG Public Key:
http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851
Fingerprint: 344F 4072 F038 BB9E B35D E6AB DDD6 D36D 4191 1851
More information about the Digitalmars-d
mailing list