[Issue 2152] Parentheses usage inconsistency.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 18 09:53:29 PDT 2008


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





------- Comment #1 from shro8822 at vandals.uidaho.edu  2008-06-18 11:53 -------
(Added to issues to make sure the code is not lost by codepad)
first example:

/* 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;
}


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


second example switches comments at line 41 & 42

Output:
oh hai! : , blah
in main: 666
oh hai! : blah = 666


-- 



More information about the Digitalmars-d-bugs mailing list