syntax sugar: std.path::buildPath instead of from!"std.path".buildPath

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 15 13:24:05 PST 2017


On Wednesday, February 15, 2017 21:03:46 Jack Stouffer via Digitalmars-d 
wrote:
> On Wednesday, 15 February 2017 at 20:54:02 UTC, Walter Bright
>
> wrote:
> > I'd like to take a step back and devise a consistent taxonomy
> > of these things
>
> Ok
>
> > 1. auto decoding dynamic arrays
>
> Narrow strings
>
> > 2. not auto decoding arrays
>
> Wide strings
>
> > 3. static arrays
>
> Do these need to be called anything other than "static arrays"?
> Also, they're not ranges, so they're usually tested with
> isStaticArray
>
> > 4. aggregates with an 'alias this' to a string
>
> isConvertibleToString
>
> > 5. ranges of characters
>
> Character range
>
> > 6. something convertible to a string
>
> Same as 4

Except that you're forgetting enums. Also, there's this mess:

enum bool isNarrowString(T) =
    (is(T : const char[]) || is(T : const wchar[])) &&
    !isAggregateType!T &&
    !isStaticArray!T;

enum bool isAutodecodableString(T) =
    (is(T : const char[]) || is(T : const wchar[])) &&
    !isStaticArray!T;

A type with alias this passes isAutodecodableString but not isNarrowString,
making for really subtle difference. Also, enums of strings pass both, which
is potentially a problem as they really should be treated the same as types
with alias this given how they need to be used in a templated function.
enums also pass isSomeString, which makes using isSomeString a no-go for any
range-based function if it doesn't then test for enums - but aggregate types
_don't_ pass isSomeString. And then there's

template isConvertibleToString(T)
{
    enum isConvertibleToString =
        (isAggregateType!T || isStaticArray!T || is(T == enum))
        && is(StringTypeOf!T);
}

So, regardless of the exact terminology, we have a whole set of very similar
but subtly different traits. And as it stands, they _will_ get screwed up
unless someone is carefully looking at each to make sure that they actually
use the right one as well as testing with various types that frequently get
missed in unit tests - like types which use alias this or enums with a base
type of string.

- Jonathan M Davis



More information about the Digitalmars-d mailing list