How to concatenate a tuple of strings at compile time?
user1205
user1205 at 1205.nc
Sat Jan 6 21:45:32 UTC 2018
On Saturday, 6 January 2018 at 21:41:56 UTC, user1205 wrote:
> On Saturday, 6 January 2018 at 21:38:41 UTC, user1205 wrote:
>> On Saturday, 6 January 2018 at 21:35:19 UTC, user1205 wrote:
>>> On Saturday, 6 January 2018 at 19:35:33 UTC, paul wrote:
>>>> Hi!
>>>>
>>>> How to concatenate a tuple of strings at compile time?
>>>> [...]
>> ```
>> template staticCat(T...)
>> if (T.length)
>> {
>> import std.array;
>> enum staticCat = [T].join();
>> }
>>
>> enum elems1 = tuple("foo", "bar");
>> enum elems2 = tuple("0", "1", "2");
>> enum elems3 = tuple("a");
>>
>> pragma(msg, staticCat!(elems1.expand));
>> pragma(msg, staticCat!(elems2.expand));
>> pragma(msg, staticCat!(elems3.expand));
>> ```
>
> +1
>
> Yeah i upvote myself. Best solution so far.
> Maybe tweak the constraint.
BTW rule of thumb: when you have the choice between template
metaprogramming and CTFE use CTFE, it's faster. The solution
based on std.array.join is CTFE.
More information about the Digitalmars-d-learn
mailing list