www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21805] New: Allow trinary expression in types

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 puremagic.com
          Reporter: qs.il.paperinik 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.

--
Apr 06