Phobosのfloat parsing algorithmをみていく。
単純化したもので考える。
nanとかinfとかはみればわかるので(単に文字比較しているだけ)そこは飛ばす。
それでも結構長いな。
| string f(alias T, Args...)() | |
| { | |
| string s; | |
| static if (T % 3 == 0) s ~= "fizz"; | |
| static if (T % 5 == 0) s ~= "buzz"; | |
| static if (T % 3 != 0 && T % 5 != 0) s ~= T.stringof; | |
| static if (Args.length > 0) return s ~ "," ~ f!(Args)(); | |
| else return s; | |
| } | |
| pragma(msg, f!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)); |
| import std; | |
| static assert(isInstanceOf!(Array, Array!char)); | |
| static assert(!isInstanceOf!(Regex, Regex!char)); | |
| static assert(isInstanceOf!(TemplateOf!(Regex!char), Regex!char)); | |
| static assert(__traits(isSame, TemplateOf!(Array!char), Array)); | |
| static assert(!__traits(isSame, TemplateOf!(Regex!char), Regex)); | |
| static if (is(Array!char == T1!Args1, alias T1, Args1...)) |
| import std.stdio; | |
| void main() | |
| { | |
| // 型情報の取得: : https://dlang.org/spec/type.html#typeof | |
| alias rt = typeof(1.0); | |
| // 型名: https://dlang.org/spec/property.html#stringof | |
| writeln(rt.stringof); // double |
| package main | |
| import "fmt" | |
| // T interface{ uint8 } だと通る | |
| func Foo[T interface{ int }, S interface{ *T }](x T) S { | |
| // ここで incompatible type: cannot use &x (value of type *T) as S value となるべき? | |
| // -> いやむしろ *T --> *uint8 になるのがおかしいのか | |
| return &x | |
よく参考にしたり追っかけるサイト集的な
| (dmd-2.088.0)$ ./bench.sh | |
| ~/dev/dlang/vibe.d ~/dev/dlang | |
| + git checkout master | |
| Already on 'master' | |
| Your branch is up to date with 'upstream/master'. | |
| + git rev-parse HEAD | |
| da8d30598bdf9401d512a46a077c62b061926e18 | |
| + set +x | |
| ~/dev/dlang/vibe.d/examples/bench-http-server ~/dev/dlang/vibe.d ~/dev/dlang | |
| + wrk -c 1000 -d 10s http://localhost:8080/ |
kubo39