with for reduced bloat

Neia Neutuladh neia at ikeran.org
Mon Dec 24 02:27:06 UTC 2018


On Mon, 24 Dec 2018 02:04:26 +0000, Michelle Long wrote:
> enum X { A, B, C}
> 
> void foo(X x);
> 
> foo(X.A);
> 
> 
> vs
> 
> 
> enum X { A, B, C}
> 
> void foo(with X x);
> 
> foo(A);

How would that deal with name collisions, static imports, and nested 
symbols?

Like the standard naming convention is to have camelCase enum value names. 
So it would be something like:

---
bool caseSensitive = false;
getopt(
  args,
  // std.getopt.config.caseSensitive, std.getopt.config.allowBundling
  caseSensitive, allowBundling,
  "c|case-sensitive", "do a case-sensitive search", &caseSensitive);
---

Yuck.

The call site determines how to refer to symbols currently. It's still a 
bit complex, dealing with imports, explicit declarations and aliases, type 
hierarchies, and with statements. This would add even more complexity.

You can reduce the amount of call-site fluff with something like:

---
enum X { a, b, c; }
static foreach (m; __traits(allMembers, X))
{
  mixin("enum " ~ m ~ " = X." ~ m ~ ";");
}
---


More information about the Digitalmars-d mailing list