www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8075] New: Optional parameters should be able to refer to previous parameters

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

           Summary: Optional parameters should be able to refer to
                    previous parameters
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: wfunction hotmail.com



void process(R)(R items, size_t maxCount = items.length) { }
unittest { process([1, 2, 3]); }


It would be great if this worked.

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


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



04:58:18 PDT ---
I really like this idea.

But there must be a provision that the expression isn't substituted wholesale.

For instance, your example should not expand to:

process([1, 2, 3], [1, 2, 3].length);

which allocates *twice*, the second time just to get the length.  It should
really expand to this:

auto items = [1, 2, 3];
process(items, items.length);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 10 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8075




Also, not sure if this is a related or a separate issue, but we should also be
able to refer to "this" object inside the optional arguments...

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