Can't print enum values
Andrey
saasecondbox at yandex.ru
Thu Aug 30 11:34:36 UTC 2018
On Thursday, 30 August 2018 at 11:09:40 UTC, vit wrote:
> args are runtime arguments.
>
> import std.experimental.all;
>
> enum MyEnum : string
> {
> First = "F_i_r_s_t",
> Second = "S_e_c_o_n_d"
> }
>
> ///alias QW(alias arg) =
> Alias!(cast(OriginalType!(typeof(arg)))arg);
> auto QW(T)(const auto ref T x){
> return cast(OriginalType!T)x;
> }
>
> void print(T...)(T args)
> {
> writeln(cast(OriginalType!(typeof(args[0])))args[0]); //
> Works...
> ///writeln(QW!(args[0])); //
> Doesn't work... MUST!
> writeln(QW(args[0]));
>
> static foreach(alias arg; args){
> static if(is(typeof(arg) : MyEnum))write(QW(arg));
> else write(arg);
> }
> write('\n');
> //writeln(staticMap!(QW, args)); //
> Doesn't work... MUST!
> }
>
> void main()
> {
> bool runTimeBool = true;
> print(MyEnum.First, 7, runTimeBool, MyEnum.Second);
> }
I want to create a reusable template for this purpose.
Why I can't use "staticMap" so that compiler it self would do
this:
>void print(T...)(T args)
>{
> writeln(cast(OriginalType!(typeof(args[0])))args[0],
> cast(OriginalType!(typeof(args[1])))args[1],
> cast(OriginalType!(typeof(args[2])))args[2],
> cast(OriginalType!(typeof(args[3])))args[3]);
>}
Just wrap some some symbol "args" with some expression at compile
time.
It is the same as in C++:
>template<Args...>
>void print(Args ...args)
>{
> writeln(UnderlyingType(args)...); // UnderlyingType is a
> function here
>}
More information about the Digitalmars-d-learn
mailing list