[ create a new paste ] login | about

Link: http://codepad.org/UV1Wsrdt    [ raw code | output | fork ]

D, pasted on Feb 9:
import std.string;
import std.stdio;


class Map(NameT, ValueT) {
    private:
        NameT[ValueT] m_realmap;

    public:
        this()
        {
        }

        ref Map insert(ref const(NameT) name, ref const(ValueT) value)
        {
            m_realmap[name] = value;
            return this;
        }

        int size()
        {
            return m_realmap.length;
        }

        ref ValueT opIndex(ref const(NameT) name)
        {
            return m_realmap[name];
        }

        ref NameT opIndex(int idx)
        {
            return m_realmap.keys[idx];
        }

        ref Map opIndexAssign(ref const(ValueT) value, ref const(NameT) name)
        {
            this.insert(name, value);
            return this;
        }
}

int main()
{
    Map!(string, string) names = new Map!(string, string);
    names["hello"] = "world";
    names["foo"] = "bar";
    for(int i=0; i<names.size(); i++)
    {
        writefln("%s => %s", names[i], names[names[i]]);
    }
    return 0;
}


Output:
1
2
3
4
Line 14: Declaration expected, not 'ref'
Line 17: Declaration expected, not 'return'
Line 25: Declaration expected, not 'ref'
Line 28: unrecognized declaration


Create a new paste based on this one


Comments: