September 28, 2021
On Tuesday, 28 September 2021 at 13:51:55 UTC, bauss wrote:
> __traits(identifier) doesn't work either.
>
> See:
>
> https://run.dlang.io/is/9cDdra

That's doing exactly what it is supposed to do. What did you expect and why do you want that?
September 28, 2021
On Tuesday, 28 September 2021 at 13:59:22 UTC, Adam D Ruppe wrote:
> On Tuesday, 28 September 2021 at 13:51:55 UTC, bauss wrote:
>> __traits(identifier) doesn't work either.
>>
>> See:
>>
>> https://run.dlang.io/is/9cDdra
>
> That's doing exactly what it is supposed to do. What did you expect and why do you want that?

Yeah but the point in this case is to get "a" as a string.

That's what I meant in my original comment and that's also what's being discussed with nameof.

Ex. if it was in C#. nameof(a) would return "a"
September 28, 2021

On Monday, 27 September 2021 at 22:51:01 UTC, russhy wrote:

>

using traits:

string enum_to_str(E)(E v) if (is(E == enum))
{
    final switch (v) with(E)
    {
        static foreach (m; __traits(allMembers, E))
        {
    case mixin(m):
            return m;
        }
    }
}

core.reflect is nicer than traits because you actually get to use actual D code

But the casting is kinda ugly, and it gives me java nightmares.. so the C++ actually feels much better

Yes the casting isn't great but all of that can be hidden with more library code.
The class oriented design of core.reflect is the way it is because it mirrors internals rather closely at this point.
I am open for improvement suggestions.

1 2 3
Next ›   Last »