www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1900] New: Template overload sets & traits templates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900

           Summary: Template overload sets & traits templates
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: wbaxter gmail.com


I'm not sure this kind of thing is supposed to work with template overload
sets, but I hope it is supposed to, as it is a pattern I see often in C++ code.
The idea is to define some "Traits" templates that define various compile-time
aspects of a particular type.

----
module main;

import std.stdio;
import A;
import B;
import generic;

void main()
{
    AClass a;
    BClass b;

    writefln("Traits!(AClass).name: ", Traits!(AClass).name);
    writefln("Traits!(BClass).name: ", Traits!(BClass).name);
    writefln("Traits!(int).name:    ", Traits!(int).name);

}
----
module A;

class AClass
{

}

template Traits(T : AClass)
{
    enum string name = "AClass";
}

----
module B;

class BClass
{

}

string func(BClass b) {
    return "BClass";
}


template Traits(T : BClass)
{
    enum string name = "BClass";
}

----
module generic;

struct Traits(T)
{
    const string name = "any";
}

----


Right now I get:

main.d(18): template instance Traits is not a template declaration, it is a
overloadset
main.d(18): Error: undefined identifier Traits!(AClass).name

(Also note the grammar error in the message "it is a overload set".)


-- 
Mar 09 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900






At least, there should be a way to merge template overload sets as it is the
case with function overload sets.

alias A.Traits Traits;
alias B.Traits Traits;
alias generic.Traits Traits;

Error: declaration Traits is already defined

Another use case:
----
template Foo(T)
{
    template Bar(U : T)
    {
    }
}

mixin Foo!(int) A;
mixin Foo!(char) B;

alias Bar!(int) bar; //error
----
Error: template instance Bar is not a template declaration, it is a overloadset


-- 
Aug 09 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900


Eldar Insafutdinov <e.insafutdinov gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |e.insafutdinov gmail.com



22:34:01 PST ---
Seems like there has not been an update on this one for quite along time. That
is obviously a big issue, there should be a way to merge template overload
sets, otherwise some great opportunities in using templates are lost. I am
using templates in Qt bindings for specifying some compile-time information for
types. My usecase is very similar to that provided by Bill. I would really like
for this one to be resolved.

Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900





 Seems like there has not been an update on this one for quite along time. That
 is obviously a big issue, there should be a way to merge template overload
 sets, otherwise some great opportunities in using templates are lost. I am
 using templates in Qt bindings for specifying some compile-time information for
 types. My usecase is very similar to that provided by Bill. I would really like
 for this one to be resolved.
 Thanks.
I think I ended up working around this by putting the essential information into the classes themselves, and then having one Traits template that covered built-in types. Another big template did bunches of static structural tests to tease the needed information out of a class. In my case that was sufficient. But it's certainly more cumbersome to deal with. Perhaps you can explain your case in a little more detail and we might be able to come up with some workaround? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 10 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|x86                         |All
         OS/Version|Windows                     |All



https://github.com/D-Programming-Language/dmd/pull/1660

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e59a33f2b639dc9a6eb431ebcf694f533916f038
fix Issue 1900 - Template overload sets & traits templates

https://github.com/D-Programming-Language/dmd/commit/cc6b7372f2efffd4c5c0314373af3b595ba06a2c


Issue 1900 & 8352 & 9235 - Implement Template Overload Set

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
             Status|NEW                         |RESOLVED
         Depends on|                            |10658
         Resolution|                            |FIXED



Template overload set has been implemented in git head.
But, merging overload set by using alias declaration is not yet implemented.
See bug 10658.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1900


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


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