[Design] return char[] or string?
Manfred Nowak
svv1999 at hotmail.com
Thu Aug 23 14:06:42 PDT 2007
Regan Heath wrote
> I assume you agree that it would be quite nice to be able to use
> properties in the error cases listed?
Not exactly properties, but one should be able to iron out those
errors. As I stated before, one can use an inner class:
class A{
private:
int _a;
public:
Property a;
this(){ a= new Property;}
class Property{
int opCall() { return _a; }
int opAssign(int assgn) { _a= assgn; return opCall(); }
int opAddAssign( int add){ _a+= add; return opCall();}
int opPostInc(){ int tmp= _a++; return tmp;}
}
}
void foo(inout A.Property i) {} // wart!!
void main(){
A a = new A();
int b;
b = a.a = 5;
a.a += 1;
a.a++;
foo(a.a);
}
In the examples given here two warts are remaining:
- classes cannot derive from basic types, therefore the type of the
formal parameter of `foo' has to be changed
- Stewarts point stays unhandled.
In fact the first wart may be closed by allowing something like
`class Property: int' or `alias int Property'.
Stewarts point does not need overloading by return type, a
conditional or lazy return `return? <expr>' would be enough. Where
`return?' has the semantics to not be evaluated if the value of the
expression `<expr>' is not needed or fed as an actual parameter to a
function at a position in the formal parameter list, where a `lazy'
parameter is declared.
-manfred
More information about the Digitalmars-d-learn
mailing list