Extended Type Design: further examples

jovo jovo at at.home
Tue Mar 20 17:37:57 PDT 2007


Andrei Alexandrescu (See Website For Email) Wrote:

> (Reposted after cleanup :o))
> 
> kris wrote:
> > How about some further example? Given these sigs:
> > 
> > struct Foo
> > {
> >    int a;
> > }
> > 
> > class Bar
> > {
> >    char[] b;
> > }
> > 
> > void fooish (inout Foo foo) {}
> > 
> > char[] barish (Bar bar) {return bar.b;}
> > 
> > 
> > 1) how do I modify the function decls to have the compiler *enforce* 
> > readonly upon the referenced content? e.g. Foo.a and Bar.b cannot be 
> > mutated within the function body?
> 
> void fooish (const ref Foo foo) {}
> 


void fooish(const ref Foo foo) {
    foo.a = 1;                   // not allowed
    foo = sam_Foo;           // allowed?
    
jovo




More information about the Digitalmars-d mailing list