Thread overview
[Issue 3666] New: Enhancement Request: Mixin Templates
Jan 02, 2010
Simen Kjaeraas
Feb 05, 2010
Nick Sabalausky
Oct 22, 2012
Andrej Mitrovic
Oct 22, 2012
Jacob Carlborg
January 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3666

           Summary: Enhancement Request: Mixin Templates
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: simen.kjaras@gmail.com


--- Comment #0 from Simen Kjaeraas <simen.kjaras@gmail.com> 2010-01-02 13:35:29 PST ---
Currently, whenever you write a template to be mixed into another type, you specify at the other type how to use the template. Most templates that are made to be mixed in, will not be used in any other way. Hence, I propose that templates may marked 'mixin' at declaration point, and 'mixin' be deemed unnecessary at their point of use. 'mixin' should still be usable for unadorned templates, and should be a no-op for mixin templates.

Proposed syntax:

mixin template foo( T ) {
  T x;
}

struct bar {
  foo!( int );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3666


Nick Sabalausky <cbkbbejeap@mailinator.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cbkbbejeap@mailinator.com


--- Comment #1 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2010-02-05 13:08:19 PST ---
A two-part addendum:

1. As D's CTFE improves, there's been more and more reason to generate a string mixin using CTFE instead of a template. Simen's point that "Most templates that are made to be mixed in, will not be used in any other way" is also true for CTFE functions. So this enhancement request should also be extended to CTFE functions in addition to templates:

-----------------------
mixin string foo2() {
    return "int a;";
}
foo2();
a = 7;
-----------------------

2. It is probably worth noting that this enhancement request can be used to trivially re-implement the current string mixin:

-----------------------
mixin string mixinString(string str) {
    return str;
}
mixinString("int a;");
-----------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3666


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich@gmail.com
         Resolution|                            |INVALID


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-21 19:47:38 PDT ---
I don't know if D had mixins or template mixins back in 2010, these look like old ideas (?). Reopen if necessary.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3666


Jacob Carlborg <doob@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob@me.com


--- Comment #3 from Jacob Carlborg <doob@me.com> 2012-10-22 00:03:07 PDT ---
These are still valid ideas and D did had templates back in 2010. Half of the proposal is already implemented, you can prefix a template declaration with "mixin". When a template is prefix with "mixin" you cannot use it like a regular template. But you still need the "mixin" keyword when mixing in the template.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------