On Tuesday, 29 December 2020 at 22:42:16 UTC, kdevel wrote:
Why is the enum to!string conversion so slow?
~~~slowenumtostringconversion.d
private enum S { A, B, C, D, };
[...]
one factor is all the template constraints that are evaluated
until the right std.conv.to overload gets selected.
Why is the enum to!string conversion so slow?
~~~slowenumtostringconversion.d
private enum S { A, B, C, D, };
version (fast) {
string resolve (E) (E e)
{
static foreach (m; __traits (allMembers, E))
if (e == __traits (getMember, E, m))
return m;
assert
On Tuesday, February 13, 2018 01:55:59 Marc via Digitalmars-d-learn wrote:
> Thanks for you always well-thought-out answer. I was going to
> print it with writefln() calls more than anywhere else so to
> avoid casts in all those places, which would make it ugly, I just
> used
>
> > enum foo = "a";
to strings, you get their actual values.
It's just that those modules specifically grab the names of the
enum members when converting enums to strings, since in all
cases other than with strings, it's generally desirable that
when converting an enum member to string, you get the name
On Monday, February 12, 2018 17:07:50 Marc via Digitalmars-d-learn wrote:
> If I have an enum like this:
> > enum S : string {
> >
> > foo = "a",
> > baa = "b"
> >
> >}
>
> when I printed it, to my surprise I get the enum
If I have an enum like this:
enum S : string {
foo = "a",
baa = "b"
}
when I printed it, to my surprise I get the enum field name
rather value:
writefln("%s v%s", S.foo, S.baa);
output:
foo vbaa
instead of
a vb
a cast solves it
Daniel Keep:
template Range(int n)
If some of you needs a version that takes 1 or 2 or 3 arguments, for the start,
stop and stride, take a look at my dlibs:
http://www.fantascienza.net/leonardo/so/dlibs/templates.html
Bye,
bearophile
Lionello Lunesu wrote:
Brad Roberts bra...@bellevue.puremagic.com wrote in message
news:alpine.deb.2.00.0903121755240.4...@bellevue.puremagic.com...
That said, I don't think this really helps the desired usecase much.
It's
useful, don't get me wrong, but still requires code to build up the
Ary Borenszweig wrote:
Lionello Lunesu wrote:
Brad Roberts bra...@bellevue.puremagic.com wrote in message
news:alpine.deb.2.00.0903121755240.4...@bellevue.puremagic.com...
That said, I don't think this really helps the desired usecase much.
It's
useful, don't get me wrong, but still
Jarrett Billingsley wrote:
There's also std.typecons
which has an enum generator that will create toString and I think
fromString functions as well.
Which should be easily portable to D1.
Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a
patch to the DMD source was not really what you expected. I just got so
anxious!
L.
Lionello Lunesu l...@lunesu.remove.com wrote in message
news:gpc4es$30a...@digitalmars.com...
Nick Sabalausky wrote:
Is there any way to do this (preferably in D1) with reflection? (ie,
without
having to manually create a conversion func/lookup for every value of
every
enum.)
Lionello Lunesu l...@lunesu.remove.com wrote in message
news:gpc4j3$30a...@digitalmars.com...
Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a
patch to the DMD source was not really what you expected. I just got so
anxious!
L.
Hey, solutions are solutions :) In fact
Your attachment is zero-byte.
Oops... Try this one..
/* Create a TupleExp out of the fields of the struct e:
* (e.field0, e.field1, e.field2, ...)
*/
e = e-semantic(sc);// do this before turning on
noaccesscheck
Nick Sabalausky wrote:
Lionello Lunesu l...@lunesu.remove.com wrote in message
news:gpc4j3$30a...@digitalmars.com...
Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a
patch to the DMD source was not really what you expected. I just got so
anxious!
L.
Hey, solutions are
cr*p, I've pasted too little. Try this one instead..
I'll use a proper diff tool next time..
/* If e.tupleof
*/
if (ident == Id::tupleof)
{
/* Create a TupleExp out of the fields of the struct e:
* (e.field0, e.field1, e.field2,
//src\dmd\mtype.c, line 5025 (in TypeEnum::dotExp, after the #endif):
/* If e.tupleof
*/
if (ident == Id::tupleof)
{
/* Create a TupleExp out of the fields of the struct e:
* (e.field0, e.field1, e.field2, ...)
*/
e = e-semantic(sc); // do this before turning
On Thu, 12 Mar 2009, BCS wrote:
Reply to Lionello,
cr*p, I've pasted too little. Try this one instead..
I'll use a proper diff tool next time..
you client is messing with you, paste-bin the sucker or add it to a bugzilla
item
Just to be sure the two don't get combined (I know
On Tue, Mar 10, 2009 at 9:54 PM, Nick Sabalausky a...@a.a wrote:
MIURA Masahiro echocham...@gmail.com wrote in message
news:gp730i$30e...@digitalmars.com...
In D2:
enum Shape: string
{
Square = Square,
Circle = Circle,
}
void main()
{
assert(cast(string) Shape.Square
19 matches
Mail list logo