[Issue 4087] New: Static Node struct of std.range.SListRange

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 13 14:39:04 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4087

           Summary: Static Node struct of std.range.SListRange
           Product: D
           Version: future
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-04-13 14:39:00 PDT ---
(This is kind of my first patch. Not using a patch command yet.)

Inside the module std.range.SListRange, at about line 1586 there is:

struct SListRange(T, Topology topology = Topology.flexible)
{
private:
    struct Node { T _value; Node * _next; }
    Node * _root;



The D2 specs here say:
http://www.digitalmars.com/d/2.0/struct.html

A struct can be prevented from being nested by using the static attribute, but
then of course it will not be able to access variables from its enclosing
scope.

I think currently all D structs are static, that feature is not implemented
yet, but once that will be implemented the Node of SListRange will be 3 words
long instead of 2 (and probably in practice 4 words), so I suggest to modify
the code like this:


struct SListRange(T, Topology topology = Topology.flexible)
{
private:
    static struct Node { T _value; Node * _next; }
    Node * _root;


Likewise, I suggest to add the static attribute to nested structs in Phobos
everywhere it's not necessary to access outer names.

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


More information about the Digitalmars-d-bugs mailing list