[ create a new paste ] login | about

Project: ncu
Link: http://ncu.codepad.org/7pBqIx25    [ raw code | output | fork ]

D, pasted on Jun 18:
/* Michal 'GiM' Spadlinski
 */
import tango.io.Stdout;

T Singleton(T)()
{
    static T singletonInstance;
    if (singletonInstance is null) {
	synchronized (T.classinfo) {
	    if (singletonInstance is null) {
		singletonInstance = new T;
		static if (is (typeof (singletonInstance.initialize))) {
		    singletonInstance.initialize();
		}
	    }
	}
    }
    return singletonInstance;
}

class Klasa
{
    int opIndex(char[] ind)
    {
        Stdout ("oh hai! : ", ind).newline;
        return 666;
    }
    int opIndexAssign(int val, char[] ind)
    {
        Stdout ("oh hai! : ") (ind) (" = ") (val).newline;
        return 0;
    }
}

alias Singleton!(Klasa) klasa;

void main()
{
    auto temp = klasa["blah"];
    Stdout ("in main: ") (temp).newline;
    klasa["blah"] = temp;
    //klasa()["blah"] = temp;
}


Output:
1
Line 41: Error: Singleton()["blah"] is not an lvalue


Create a new paste based on this one


Comments: