Thread overview
[Issue 1303] New: ParameterTypeTuple asserts false on parameterless function
Jul 01, 2007
d-bugmail
Jul 01, 2007
d-bugmail
Dec 09, 2008
d-bugmail
July 01, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1303

           Summary: ParameterTypeTuple asserts false on parameterless
                    function
           Product: D
           Version: 2.000
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: patch
          Severity: normal
          Priority: P4
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: dhasenan@gmail.com


ParameterTypeTuple should return an empty TypeTuple for parameterless functions.

Why would this not cause problems with existing code? Well, assert(false) always immediately stops compilation. Nobody can possibly use ParameterTypeTuple on a parameterless function, not even to check if it's void, unless they mean to do so manually, in which case they might as well crack open the code in a text editor and check.

However, all the invalid cases, such as:
---
void foo() {}
ParameterTypeTuple!(foo)[0] x;
---

These are still caught at compile time with a relevant warning.

Note that library writers currently have to duplicate the template in order to provide this basic functionality. Also note that this behavior is undocumented.


Patch:
--- traits.d    2007-07-01 08:50:00.000000000 -0400
+++ traits.d    2007-07-01 08:31:34.000000000 -0400
@@ -18,6 +18,7 @@
  */



 module std.traits;

+private import std.typetuple;



 /***

  * Get the type of the return value from a function,

@@ -69,7 +70,7 @@
     else static if (is(dg P == P*))

        alias ParameterTypeTuple!(P) ParameterTypeTuple;

     else

-       static assert(false, "parameter required");

+       alias TypeTuple!() ParameterTypeTuple;

 }


-- 

July 01, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1303





------- Comment #1 from dhasenan@gmail.com  2007-07-01 08:01 -------
Created an attachment (id=149)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=149&action=view)
lets ParameterTypeTuple handle parameterless funcs

Botched the in-text patch (linebreak issue); this should work.


-- 

December 09, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1303


bugzilla@digitalmars.com changed:

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




------- Comment #2 from bugzilla@digitalmars.com  2008-12-09 16:47 -------
This seems to work fine on parameterless functions.


--