www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4886] New: Template (alias) tuple parameters cannot take .length property in compiletime

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

           Summary: Template (alias) tuple parameters cannot take .length
                    property in compiletime
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: zan77137 nifty.com


--- Comment #0 from SHOO <zan77137 nifty.com> 2010-09-18 00:54:05 PDT ---
This code doesn't work!
----
auto test(ARGS...)()
{
    int[ARGS.length] x;
    return x;
}

void main(string[] args)
{
    void func(){  }
    auto t = test!(func)();
}
----


Results:
prog.d(3): Error: identifier 'length' of 'ARGS.length' is not defined
prog.d(3): Error: index is not a type or an expression
prog.d(10): Error: template instance prog.main.test!(func) error instantiating


Workaround is this:
----
size_t lengthof(ARGS...)()
{
    return ARGS.length;
}

auto test(ARGS...)()
{
    int[lengthof!(ARGS)()] x;
    return x;
}

void main(string[] args)
{
    void func(){  }
    auto t = test!(func)();
}
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 18 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4886


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2010-09-19 17:44:54 PDT ---
Reduced test case:

template Foo(T...) {
    int[T.length] x;
}
static assert(Foo!(1, 2, 3).x.length == 3);
void main() {}



A workaround:

template Foo(T...) {
    int[cast(int)T.length] x;
}
static assert(Foo!(1, 2, 3).x.length == 3);
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 19 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4886



--- Comment #2 from Shin Fujishiro <rsinfu gmail.com> 2010-09-22 22:04:28 PDT
---
Created an attachment (id=764)
Patch against dmd r680, fixes resolveHelper()

This patch fixes the reported issue and bug 2953 (D2).  It passed dmd, druntime
and phobos tests.

The patch also fixes the following problems:
--------------------
struct R
{
    alias int T;
}
struct S
{
    R r;
    alias r this;
}
S.T x;                  // (10)
int[S.r.offsetof] y;    // (11)
--------------------
% dmd -o- -c test.d
test.d(10): Error: S.T is used as a type
test.d(11): Error: no property 'offsetof' for type 'R'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4886


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

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


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2012-05-30 20:38:39 PDT ---
All of cases work in 2.060head.

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