D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5898 - [const] std.typecons.Rebindable.get() should be const-correct
Summary: [const] std.typecons.Rebindable.get() should be const-correct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-27 07:50 UTC by kennytm
Modified: 2011-10-10 19:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-04-27 07:50:31 UTC
Currently std.typecons.Rebindable.get() is not a const function. This makes the a rebindable member not usable in a const function, e.g.

------------------------------------------
import std.typecons;
class Y {
    string t;
}
class X {
    Rebindable!(const(Y)) y;
    override string toString() const {
        return y.t;   // Error
    }
}
------------------------------------------
x.d(8): Error: function std.typecons.Rebindable!(const(Y)).Rebindable.get () is not callable using argument types ()
------------------------------------------

There should be a const get() method, e.g.


diff --git a/std/typecons.d b/std/typecons.d
index 7d130ca..bbf7615 100644
--- a/std/typecons.d
+++ b/std/typecons.d
@@ -920,6 +920,9 @@ template Rebindable(T) if (is(T == class) || is(T == interface) || isArray!(T))
             @property ref T get() {
                 return original;
             }
+            @property const(T) get() const {
+                return original;
+            }
 
             alias get this;
         }