www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1303] New: ParameterTypeTuple asserts false on parameterless function

reply d-bugmail puremagic.com writes:
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;

 }


-- 
Jul 01 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1303






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.


-- 
Jul 01 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1303


bugzilla digitalmars.com changed:

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





This seems to work fine on parameterless functions.


-- 
Dec 09 2008