SugarCpp icon indicating copy to clipboard operation
SugarCpp copied to clipboard

C++11 Initializer Lists

Open ozra opened this issue 11 years ago • 0 comments

I humbly propose two alternative syntaxes:

Alternative 1:

  • Akin to the C++ colon beginning init lists, and expanding on the "list theme" by using colon as sort of a list item bullet, thereby making a clear distinction between the init-list and the constructor code block.
class SomeClass
    SomeClass(int a, int b)
        : a {a}
        : b {(a + b) / 2}

        if a > 9
            d.seed(47)
        elif a > 3
            d.seed(23)
        else
            d.seed(13)

        c = d.rnd()

    a : real
    b : real32
    c : real
    d : SomeRandomizer

Alternative 2:

  • Akin to the modifiers in the class block, now block defining modifiers within the constructor.
class SomeClass
    SomeClass(int a, int b)
        [init]
        a {a}
        b {(a + b) / 2}

        [construct]
        if a > 9
            d.seed(47)
        elif a > 3
            d.seed(23)
        else
            d.seed(13)

        c = d.rnd()

    a : real
    b : real32
    c : real
    d : SomeRandomizer

I prefer the first one.

ozra avatar Dec 08 '14 12:12 ozra