Choosing between enum arrays or AliasSeqs

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 24 12:41:46 PDT 2017


Given

    enum e = ['a', 'b', 'c'];

    import std.meta : AliasSeq;
    enum a = AliasSeq!['a', 'b', 'c'];

is it somehow possible to convert (at compile-time) `e` to `a`?

Is it cheaper CT-performance wise to use AliasSeq instead of enum 
static arrays?

My use case is expressed by the TODOs in the following code 
snippet


import std.algorithm : among;

/** English indefinite articles. */
enum englishIndefiniteArticles = [`a`, `an`];

/** English definite articles. */
enum englishDefiniteArticles = [`the`];

/** English definite articles. */
enum englishArticles = englishIndefiniteArticles ~ 
englishDefiniteArticles;

/** Check if $(D c) is a Vowel. */
bool isEnglishIndefiniteArticle(C)(C c)
     if (isSomeChar!C)
{
     return cast(bool)c.among!(`a`, `an`); // TODO reuse 
englishIndefiniteArticles
}

/** Check if $(D c) is a Vowel. */
bool isEnglishDefiniteArticle(C)(C c)
     if (isSomeChar!C)
{
     return cast(bool)c.among!(`the`); // TODO reuse 
englishDefiniteArticles
}

/** Check if $(D c) is a Vowel. */
bool isEnglishArticle(C)(C c)
     if (isSomeChar!C)
{
     return cast(bool)c.among!(`a`, `an`, `the`); // TODO reuse 
englishArticles
}



More information about the Digitalmars-d-learn mailing list