xxxxxxxxxx
module test;
enum CompSem
{
EQUAL,
LESSTHAN
}
template ltFunc(alias pred)
{
bool ltFunc(T)(T a, T b)
{
return !pred(a, b) && !pred(b, a);
}
}
template S(CompSem sem, alias pred)
{
import std.meta : Alias;
static if (sem == CompSem.EQUAL)
{
alias S = pred;
}
else
{
alias S = ltFunc!pred;
}
}
void main()
{
alias x = S!(CompSem.LESSTHAN, ((b, c) => b < c));
alias y = S!(CompSem.EQUAL, ((b, c) => b == c));
import std.stdio;
writeln(x(4, 4));
writeln(x(4, 5));
writeln(y(4, 4));
writeln(y(4, 5));
}