Summary: TemplateThisParameter should change member function's
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Kenji Hara <> 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;;
    // T == X, and foo is mutable member function.
    // then we can call it with mutable object.

    immutable(X) ix;;
    // 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.


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

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:
------- You are receiving this mail because: -------

Reply via email to