From D Wiki
Revision as of 00:33, 30 July 2013 by Dawg (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Title: Add enum E(T) = expression; eponymous template support
DIP: 42
Version: 1
Status: Implemented
Load: Design Details
Created: 2013-06-24
Last Modified: 2013-06-24
Language: D2
Breaks: Nothing (extension)
Links: DMD Pull request


This pattern has become quite common in D:

   template isIntegral(T) {
     enum isIntegral = is(T : long) || is(T : ulong) || ...;

Analogously to struct S(T), the enum manifest constant could be written as:

   enum isIntegral(T) = is(T : long) || is(T : ulong) || ...;

This is a natural fit for D. It does not break any existing code, and is simple to implement - it's just a rewrite in the parser.


The pattern is common, and a bit awkward. It's worth supporting the new syntactic sugar.


This document has been placed in the Public Domain.