Choosing between enum arrays or AliasSeqs

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 24 15:38:29 PDT 2017


On Thursday, 24 August 2017 at 19:41:46 UTC, Nordlöw wrote:
> 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
> }

https://dlang.org/phobos/std_meta.html#aliasSeqOf


More information about the Digitalmars-d-learn mailing list