[Issue 8669] New: TemplateThisParameter should change member function's qualifier
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 16 07:48:27 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8669
Summary: TemplateThisParameter should change member function's
qualifier
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: k.hara.pg at gmail.com
--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-09-16 07:49:19 PDT ---
With current implementation, a member function with TemplateThisParameter is
not generated based on each 'this' type.
struct X {
void foo(this T)() {}
}
void main() {
X mx;
mx.foo();
// T == X, and foo is mutable member function.
// then we can call it with mutable object.
immutable(X) ix;
ix.foo();
// T == immutable(X), but foo is still *mutable* member function.
// then we cannot call it with immutable object
}
foo is always instantiated as mutable member function, and always cannot be
called with non-mutable object.
I think this is not convenient in many cases.
====
Enhancement:
If foo is called from immutable object, foo should be instantiated as immutable
member function. Following is detailed explanation of compiler behavior to
realize it.
The declaration of foo is expanded as like follows.
struct X {
template foo(this T) {
void foo() {}
}
}
If T is immutable type, compiler would wrap the template body into
StorageClassDeclaration.
struct X {
template foo(this T) { // if T == immutable
immutable{ // <-- automatically wrapped by the compiler
void foo() {} // now foo is immutable member function
}
}
template foo(this T) { // if T == const
const{ // <-- automatically wrapped by the compiler
void foo() {} // now foo is const member function
}
}
// as well, if T == shared, shared const, inout, and shared inout
}
This would make forwarding operations more convenient, e.g. std.typecons.Proxy.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list