Why we cannot use string in mixins?
Jesse Phillips via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 29 08:07:57 PST 2016
On Sunday, 28 February 2016 at 03:08:14 UTC, mahdi wrote:
> Thanks.
>
> So the author was plain wrong about using enums instead of
> strings. The misconception is due to assuming we can use
> `string` variables at compile time but we cannot (as they are
> run-time data).
Not exactly either.
#define str "My string for use"
In C people know the processor which creates a "manifest const."
In D, it was chosen to reuse enum as the keyword to declare
manifest const.
enum string str = "My string for use";
But in D, we don't required declaring the type everywhere so you
can just specify a storage class:
const str = "My string for use";
Combine the things together and you create a compile time string
without specifying that the type is string.
enum str = "My string for use";
More information about the Digitalmars-d-learn
mailing list