On Wednesday, 20 June 2018 at 14:39:48 UTC, Per Nordlöw wrote:
Is there a way to avoid compile-time-string-concat plus mixin
here?
Using __traits(getMember, ...) should compile faster, right?
T toDefaulted(T)(scope const(char)[] value, T defaultValue) @safe
pure nothrow @nogc
if (is(T ==
On Wednesday, 20 June 2018 at 09:54:29 UTC, Per Nordlöw wrote:
T toDefaulted(T)(scope const(char)[] value,
T defaultValue) @safe pure nothrow @nogc
if (is(T == enum))
{
switch (value)
{
static foreach (index, member; __traits(allMembers, T))
{
On Wednesday, June 20, 2018 09:37:00 Per Nordlöw via Digitalmars-d-learn
wrote:
> On Wednesday, 20 June 2018 at 09:27:14 UTC, Per Nordlöw wrote:
> > On Monday, 18 June 2018 at 21:10:03 UTC, Steven Schveighoffer
> >
> > wrote:
> >> It just means re-doing std.conv.to, which is pretty hairy, but
>
On Wednesday, 20 June 2018 at 09:37:00 UTC, Per Nordlöw wrote:
AFAICT, string-to-enum-conversion must include a switch
containing a static foreach over all the enumerators, right?
My suggestion for nothrow @nogc string-to-enum conversion with
default value
T toDefaulted(T)(scope
On Wednesday, 20 June 2018 at 09:52:04 UTC, Per Nordlöw wrote:
My suggestion for nothrow @nogc string-to-enum conversion with
default value
T toDefaulted(T)(scope const(char)[] value,
T defaultValue) @safe pure nothrow @nogc
if (is(T == enum))
{
switch (value)
{
On Wednesday, 20 June 2018 at 09:27:14 UTC, Per Nordlöw wrote:
On Monday, 18 June 2018 at 21:10:03 UTC, Steven Schveighoffer
wrote:
It just means re-doing std.conv.to, which is pretty hairy, but
also pretty well-organized.
Ok. Where in std.conv do the string-to-enum conversions take
place?
On Monday, 18 June 2018 at 21:10:03 UTC, Steven Schveighoffer
wrote:
It just means re-doing std.conv.to, which is pretty hairy, but
also pretty well-organized.
Ok. Where in std.conv do the string-to-enum conversions take
place?
On 6/18/18 4:48 PM, Per Nordlöw wrote:
The problem with this code is that throwing exceptions for the default
case is costly at least with dmd. Is there another way to do this?
Yes, have an internal implementation which doesn't throw, but rather
returns an error code. Then you can call that
On Monday, 18 June 2018 at 20:48:55 UTC, Per Nordlöw wrote:
T toDefaulted(T, S, U)(S value, /*lazy*/ U defaultValue)
if (is(typeof(() { T r = defaultValue; }))) // TODO use
std.traits.isAssignable!(T, U) ?
why not just make it
T toDefaulted(T, S)(S value, T defaultValue)
and forget U
I have a nothrow variant of std.conv.to defined as follows:
T toDefaulted(T, S, U)(S value, /*lazy*/ U defaultValue)
if (is(typeof(() { T r = defaultValue; }))) // TODO use
std.traits.isAssignable!(T, U) ?
{
try
{
import std.conv : to;
return value.to!T;
}
catch
10 matches
Mail list logo