私の考えでは、関数の純粋さの力は、深いコード パスが副作用のないものとして検証できるときです。純粋な指定子の内部にあるコード ツリーの規模と、コードの再利用のレベルについて、人々の経験はどのようなものですか?
私が見つけたいくつかのこと:
std.algorithm
はほとんど としてマークされていませんpure
が、インスタンス化関数または mixin の純度を要求するアルゴリズムの純粋なバージョンによって、または純粋な指定子自体が静的にポリモーフィックであることによって、大部分が純粋である可能性があります。
のような便利なコンバーターto!string( someInt )
は現在純粋ではありません。
ユーザー定義の構造体 には、次のような問題があるようです (以下に示すように)
。
次のコードは現在、DMD 2.052 win 32 ビットで複数のエラーを発生させます。
struct InnerStruct
{
pure this(this) {}
pure ~this() {}
}
struct OuterStruct
{
InnerStruct innerStruct;
pure this(this) {}
pure ~this() {}
}
pure void somePureFunc()
{
OuterStruct s1 = OuterStruct(); // pure nested destructor does not compile
OuterStruct s2 = s1;
InnerStruct is1 = InnerStruct(); // pure non-nested destructor seems to compile
InnerStruct is2 = is1; // pure non-nested postblit does not compile
}
void main()
{
somePureFunc();
}
pure_postblit.d(18): Error: pure function 'somePureFunc' cannot call impure function '__cpctor'
pure_postblit.d(20): Error: pure function 'somePureFunc' cannot call impure function '__cpctor'
pure_postblit.d(18): Error: pure function 'somePureFunc' cannot call impure function '~this'
pure_postblit.d(17): Error: pure function 'somePureFunc' cannot call impure function '~this'