[Issue 2984] New: Failure to find front/back/popBack/popFront/etc should fall back to opApply

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 15 15:04:23 PDT 2009


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

           Summary: Failure to find front/back/popBack/popFront/etc should
                    fall back to opApply
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: 2korden at gmail.com


I have a Vector class which is modeled after std::vector. As such, it has
front, back, popBack but no popFront method. DMD2.029 fails to compile foreach
over the vector because it lacks popFront even though there are opApply
overloads for it. Marking it as a regression since it used to compile with
DMD2.028 although it used other primitive names. Here is a cut-down code to
reproduce the problem:

module Vector;

public struct Vector(Type)
{
    private uint    _size = 0;
    private Type[]  _elements = null;

    uint length()
    {
        return _size;
    }

    bool empty()
    {
        return _size == 0;
    }

    void popBack()
    in
    {
        assert(_size >= 1);
    }
    body
    {
        --_size;
    }

    Type back()
    in
    {
        assert(!empty());
    }
    body
    {
        return _elements[_size-1];
    }

    Type front()
    in
    {
        assert(!empty());
    }
    body
    {
        return _elements[0];
    }

    int opApply(int delegate(ref Type value) dg)
    {
        for(uint i=0; i<_size; ++i)
        {
            int result = dg(_elements[i]);
            if( result != 0 ) {
                return result;
            }
        }

        return 0;
    }

    int opApply(int delegate(ref uint index, ref Type value) dg)
    {
        for(uint i=0; i<_size; ++i)
        {
            int result = dg(i, _elements[i]);
            if( result != 0 ) {
                return result;
            }
        }

        return 0;
    }
}

void main()
{
    Vector!(int) v;
    foreach (int i; v) {
        // do nothing
    }
}

-- 
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