> On 2011-05-17 23:48:35 -0400, Andrej Mitrovic > <andrej.mitrov...@gmail.com> said: > > > So how do functions which take such a parameter look like? > > What do you mean by what they'll look like? They'll look like how you > wrote them. I'm not sure I understand the question... but I'll still > try to answer. > > > > void bar(ref Foo a, const(Foo) ref b) { } > > > > void bar(ref Foo a, ref const(Foo) b) { } > > With my patch, assuming Foo is a class, the above is the same thing as: > > void bar(ref Foo ref a, const(Foo) ref b) { } > > void bar(ref Foo ref a, ref const(Foo ref) b) { } > > The postfix "ref" represents the object's rebindable reference, while > the prefix "ref" is a non-rebindable reference to that object reference. > > I'm aware that using "ref" both for variable reference and object > reference can look a little confusing at times. Changing the postfix > "ref" for another symbol would help make things clearer. That said, > given that most of the time you don't have to write the "ref" part -- > as it is implicit -- I'm not sure it is worth spending a new character > token for it either. > > - - - > > Also, I usually prefer to stick the postfix "ref" to the closing > parenthesis, no space in between, like this: > > const(Foo)ref > > It does not matter at all when parsing, but I find that this way I'm > more inclined to see the ref as part of the type rather than some kind > of separate attribute. Of course you have to leave the space when there > is no attribute and no parenthesis (as in "Foo ref"), but for those > cases I just drop the "ref" because it's implicit anyway. > > This is just my personal style. > > > -- > Michel Fortin > michel.for...@michelf.com > http://michelf.com/
Given that reference types do not support the semantics asked for at all (with transitive const/immutable), I think this is as consistent as it can get. (also way better than "obj<insert storage specifier here>" all over the place.) Am I correct when I assume that, if Foo is a class then Foo ref is the same type as Foo, but const(Foo ref)ref is not a valid type while const(Foo) ref is a valid type? Are there any strange implications for pattern matching? For example: alias const(Foo)ref T; static if(is(T U : const(U)ref){ //would it match? If yes, what is U? Foo ref? } Timon