[Issue 21805] New: Allow trinary expression in types

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 6 16:15:16 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21805

          Issue ID: 21805
           Summary: Allow trinary expression in types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: qs.il.paperinik at gmail.com

Allow
    expr ? type1 : type2
where a type is expected.

Type:
+   ConditionalType
    TypeCtors[opt] BasicType TypeSuffixes[opt]

+ ConditionalType:
+   OrOrExpression ? BasicType : ConditionalType

Some small conditions don't warrant 4 (or 8) LoC for defining an alias.

    static if (bits > 32)
    {
        alias Word = ulong;
    }
    else
    {
        alias Word = uint;
    }

versus

    alias Word = bits > 32 ? ulong : uint;

Another win is you can use the conditional type without having to define an
alias.

--


More information about the Digitalmars-d-bugs mailing list