www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 599] New: ExpressionTuple doesn't match template's alias parameters

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

           Summary: ExpressionTuple doesn't match template's alias
                    parameters
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: lovesyao hotmail.com


template test2(alias s){
  alias s[0] test2;
}

void test(T...)(T tl){
  alias tl tl2;//ok
  assert(test2!(tl)==0);//doesn't match alias template declaration
}

void main(){
  test(0,"a",'a');
}


-- 
Nov 25 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=599


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |rejects-valid





Here's what I get (DMD 0.121, Windows):

bz599.d(7): template instance test2!(_param_0,_param_1,_param_2) does not match
any template declaration
bz599.d(7): Error: void has no value
bz599.d(7): Error: incompatible types for ((test2!(_param_0,_param_1,_param_2))
== (0)): 'void' and 'int'
bz599.d(11): template instance bz599.test!(int,char[1u],char) error
instantiating

The problem seems to be that it doesn't like a tuple as a template alias
parameter.  From what I can make out of the spec, it ought to work.


-- 
Sep 10 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=599






On second thoughts, it seems the problem is that test2!(t1) expands to
test2!(0, "a", 'a'), which is three parameters, whereas (alias s) is only one. 
Still, it ought to be possible to pass tuples as alias parameters.


-- 
Sep 10 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=599


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





Tuples are expanded before arguments are matched to parameters, so they cannot
be passed as alias parameters. This is by design.


-- 
Jun 30 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=599






If you need to allow someone to do this for your template, try this:

struct Tpack(T...)
{
  static alias T Tpl;
}

test2!(Tpack!(T))

template test2(alias s){
  alias s.Tpl[0] test2;
}

(Or some variate of that, I didn't test this but have made the trick work
before)


-- 
Jun 30 2008