...ing logging 4.0

はてなブログに移行しました。D言語の話とかいろいろ。

std.bind

練習練習っと.

import std.bind, std.stdio, std.process;

bool less(T)(T a, T b)
{
    return a < b;
}

void main()
{
    writefln("10 < 20 =? ", less(10, 20));
    
    auto less10 = bind(&less!(int), _0, 10);
    writefln(" 5 < 10 =? ", less10(5));
    writefln("20 < 10 =? ", less10(20));
    
    auto greater10 = bindAlias!(less!(int))(10, _0);
    writefln(" 5 > 10 =? ", greater10(5));
    writefln("20 > 10 =? ", greater10(20));
    
    system("pause");
}
C:\D\projects\hello>hello
10 < 20 =? true
 5 < 10 =? true
20 < 10 =? false
 5 > 10 =? false
20 > 10 =? true