www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21902] New: Templated Aliases and Enums should support

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

          Issue ID: 21902
           Summary: Templated Aliases and Enums should support
                    restrictions
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: per.nordlow gmail.com

Template aliases and enums should support restrictions as, for instance,

enum maxAlignment(Ts...)
if (Ts.length > 0)
{
    size_t result = 0;
    static foreach (T; Ts)
        if (T.alignof > result) result = T.alignof;
    return result;
}();

Currently it's only possible to simplify definitions such as

template maxAlignment(Ts...)
if (Ts.length > 0)
{
    enum maxAlignment =
    {
        size_t result = 0;
        static foreach (T; Ts)
            if (T.alignof > result) result = T.alignof;
        return result;
    }();
}

to

enum maxAlignment(Ts...)
{
    static assert(Ts.length > 0);
    size_t result = 0;
    static foreach (T; Ts)
        if (T.alignof > result) result = T.alignof;
    return result;
}();

because of this limitation.

--
May 07