March 21, 2008
I'm playing around with templates and mixins of different types, in an effort to
make a property struct with all manners of overloaded operators (as per
Alternative solutions to returning ref types. in digitalmars.D).

Now, when I use this thing and do something wrong, I get error messages with
very user-unfriendly texts. For instance:

/////////////////

int _a;
property!(int, properties.read) a = &_a; // properties.read means only operators
                                  // that do not change the data are overloaded.
a += 4; // this lines leads to the errors below

/////////////////

test.d(8): Error: 'a' is not a scalar, it is a
  _property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")
test.d(8): Error: incompatible types for ((a) += (4)):
  '_property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")' and 'int'
test.d(8): Error: 'a' is not of arithmetic type, it is a
  _property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")


As you can see, hardly user-friendly. Now, how can I make them more readable? Do
I need to overload all the other operators with templated functions with static
asserts?

-- Simen
March 22, 2008
Reply to Simen,

> I'm playing around with templates and mixins of different types, in an
> effort to
> make a property struct with all manners of overloaded operators (as
> per
> Alternative solutions to returning ref types. in digitalmars.D).
> Now, when I use this thing and do something wrong, I get error
> messages
> with
> very user-unfriendly texts. For instance:
> /////////////////
> 
> int _a;
> property!(int, properties.read) a = &_a; // properties.read means only
> operators
> // that do not change the data are
> overloaded.
> a += 4; // this lines leads to the errors below
> 
> /////////////////
> 
> test.d(8): Error: 'a' is not a scalar, it is a
> _property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")
> test.d(8): Error: incompatible types for ((a) += (4)):
> '_property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")'
> and
> 'int'
> test.d(8): Error: 'a' is not of arithmetic type, it is a
> _property!(int,void,"+,-,*,/,%,&,|,^,<<,>>,>>>,~,in","+,-","")
> As you can see, hardly user-friendly. Now, how can I make them more
> readable? Do
> I need to overload all the other operators with templated functions
> with
> static
> asserts?

I wish they were better (I once has a compile that managed to flush my 2000+ line scroll back buffer x-). But I'm not sure how you could do it without loosing information that the user needs to see.