|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.bugs - [Issue 2027] New: No way to declare only the reference 'const' or 'invariant' for reference types.
http://d.puremagic.com/issues/show_bug.cgi?id=2027 Summary: No way to declare only the reference 'const' or 'invariant' for reference types. Product: D Version: 2.012 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: htvennik zonnet.nl While using D I often want a reference to a class object to be invariant, while the object itself should be mutable. Or, in my current case, I want a delegate variable to be invariant (i.e. the reference may not change), but I do not want that only a invariant function may be assigned to it on initialization... This is obviously an undesirable limitation of the D 2.0 type system. Probably there should be some storage class for these cases. The following piece of code demonstates the problem: class A { private: invariant Object o_; this(Object o) { o_ = o; // error, cannot implicitly convert to invariant } } Because o_ is of type invariant(Object), it cannot be assigned a value of type Object, which is perfecly correct. But I do not intend o_ to be of type invariant(Object), I only want o_ to reference the same instance of Object, throughout the lifetime of the instance of class A, and thus forbid re-assignment... -- Apr 24 2008
That's not a bug, that's a request for head-const. :-) Apr 24 2008
|