On Wednesday, 4 December 2024 at 21:33:46 UTC, Salih Dincer wrote:
> Maybe I'm misunderstanding...
Now I get it! In fact, we bind a chosen argument. This reveals the inadequacy of the name chosen for the library. I've made it better by adding a few lines of code:
auto hello(T)(T a, T b, T c, T d, T e)
=> a~b~c~d~e;
enum msg { h = "h", e = "e", l = "l", o = "o" }
void main()
{
with(msg)
{
assert(bindArgument!(hello, 0, h)(e,l,l,o) == "hello");
assert(bindArgument!(hello, 1, e)(h,l,l,o) == "hello");
assert(bindArgument!(hello, 2, l)(h,e,l,o) == "hello");
assert(bindArgument!(hello, 3, l)(h,e,l,o) == "hello");
assert(bindArgument!(hello, 4, o)(h,e,l,l) == "hello");
alias Fun = bindArgument!(hello, 5, e);
//Fun(h, l, l, o).writeln; //error
}
}
template bindArgument(alias func, size_t N, fixedArgs...)
{
static auto bindArgument(A...)(A argsRest)
if(N <= argsRest.length)
{
static if (N == 0)
return func(fixedArgs[0], argsRest);
else
return func(argsRest[0 .. N],
fixedArgs[0],
argsRest[N .. $]);
}
}
SDB@79