Lstr

式を埋め込み可能な文字列リテラルを構築します

template Lstr (
alias str
) if (
isSomeString!(typeof(str))
) {
enum string Lstr;
}

Examples

1 {
2     int a = 12, b = 13;
3 
4     assert(mixin(Lstr!"aaaa") == "aaaa");
5 
6     // %[ から %] までがDの任意の式を表す。
7     assert(mixin(Lstr!`foo%[a+b%]bar%[a+10%]%[a%]`) == "foo25bar2212");
8 }
9 
10 {
11     int a = 12;
12     string b = "3";
13     auto t = tuple(a, b);
14     string str = mixin(Lstr!`Element1 : %[t[0]%], Element2 : %[t[1]%]`);
15     assert(str == `Element1 : 12, Element2 : 3`);
16 }
17 
18 {
19     int a = 12;
20     assert(mixin(Lstr!`foo%[a%]`) == "foo12");
21     assert(mixin(Lstr!`foo%[a%`) == `foo%[a%`);
22     assert(mixin(Lstr!`foo%[a`) == `foo%[a`);
23     assert(mixin(Lstr!`foo%[%]`) == `foo`);
24     assert(mixin(Lstr!`foo%[`) == `foo%[`);
25     assert(mixin(Lstr!`foo%`) == `foo%`);
26 }

Meta