に送信します。関数のテンプレート引数としてDのsort
関数を送信しようとしています。私はそれが動作テンプレート引数なしでsort
を使用する場合: テンプレート関数をテンプレート関数の引数としてD
import std.stdio,std.algorithm,std.functional;
void main()
{
auto arr=pipe!(sort)([1,3,2]);
writeln(arr);
}
私はテンプレート引数でsort
を使用しようとするただし、:
import std.stdio,std.algorithm,std.functional;
void main()
{
auto arr=pipe!(sort!"b<a")([1,3,2]);
writeln(arr);
}
私はエラーを取得する - main.d(5): Error: template instance sort!("b<a") sort!("b<a") does not match template declaration sort(alias less = "a < b",SwapStrategy ss = SwapStrategy.unstable,Range)
それはなぜ起こるのですか? sort!"b<a"
はそれ自体で動作し、同じ引数と戻り値の型をsort
としています。なぜpipe
はsort
を受け取りますが、sort!"b<a"
を受け入れないのですか?そして、私がしようとしているものに対して正しい構文がありますか?
UPDATE
OK、私はsort
機能をラップしようとしました。次のコードは動作します:
import std.stdio,std.algorithm,std.functional,std.array;
template mysort(string comparer)
{
auto mysort(T)(T source)
{
sort!comparer(source);
return source;
}
}
void main()
{
auto arr=pipe!(mysort!"b<a")([1,3,2]);
writeln(arr);
}
なぜ元のバージョンは動作しませんか?これは余分なテンプレートのパラメータのためですsort
がかかりますか?
は、機能をパイプが、私はそうではありません参照してください。 –
@IdanArye: 'pipe'は、それを引数(' alias pipe!(f)piped;)から分離し、その後に 'piped([1,2,3]);') – kennytm
テンプレート化された関数自体を 'piped'するような' alias'をしてはいけませんか? –