Can't print enum values
vit
vit at vit.vit
Thu Aug 30 11:09:40 UTC 2018
On Thursday, 30 August 2018 at 10:41:58 UTC, Andrey wrote:
> Hello,
> This code doesn't print enum values:
>>import std.meta;
>>import std.traits;
>>import std.stdio;
>>
>>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);
>>
>>void print(T...)(T args)
>>{
>> writeln(cast(OriginalType!(typeof(args[0])))args[0]); //
>> Works...
>> writeln(QW!(args[0])); //
>> Doesn't work... MUST!
>>
>> writeln(staticMap!(QW, args)); //
>> Doesn't work... MUST!
>>}
>>
>>void main()
>>{
>> bool runTimeBool = true;
>> print(MyEnum.First, 7, runTimeBool, MyEnum.Second);
>>}
>
> Must print "F_i_r_s_t" and "S_e_c_o_n_d", not just "First" and
> "Second".
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);
}
More information about the Digitalmars-d-learn
mailing list