B Revzin - if const expr isn't broken (was Re: My Meeting C++ Keynote video is now available)

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 18 20:29:08 UTC 2019

On Fri, Jan 18, 2019 at 08:03:48PM +0000, Mark via Digitalmars-d-announce wrote:
> Why not do away with AliasSeq and use strings all the way?
> string Constify(string type)
> {
>     // can add input checks here
>     return "const(" ~ type ~ ")";
> }
> void main()
> {
>     import std.algorithm : map;
>     enum someTypes = ["int", "char", "bool"];
>     enum constTypes = map!Constify(someTypes);
>     mixin(constTypes[0] ~ "myConstInt = 42;"); // int myConstInt = 42;
> }
> Represent types as strings, CTFE them as you see fit, and output a
> string that can then be mixin'ed to use the actual type. :)

That would work, but it would also suffer from all the same problems as
macro-based programming in C.  The compiler would be unable to detect
when you accidentally pasted type names together where you intended to
be separate, the strings may not actually represent real types, and
generating code from pasting / manipulating strings is very error-prone.
And you could write very unmaintainable code like pasting partial tokens
together as strings, etc., which makes it hard for anyone else
(including yourself after 3 months) to understand just what the code is
trying to do.

Generally, you want some level of syntactic / semantic enforcement by
the compiler when you manipulate lists (or whatever other structures) of


INTEL = Only half of "intelligence".

More information about the Digitalmars-d-announce mailing list