I try to create an std::initializer_list of bind values, compile time using the following function.
However, I can't get it correctly.
template<class T, int N> auto b(T t) -> auto
{
if constexpr (N == 0) {
return std::initializer_list<????????>{ std::bind(t, 0) };
}
else {
return std::initializer_list { b<decltype(t), N-1>(t), std::bind(t, 0) };
}
}
All this is to avoid code like:
char F(int c) { return 42; /* do something with c or course */ }
// ....
auto fs = { std::bind(F, 0),
std::bind(F, 1),
std::bind(F, 2),
std::bind(F, 3),
std::bind(F, 4),
std::bind(F, 5) /*, etc ...*/};
Is there anyone who can guide me towards a feasible solution?
I would recommend having a
std::arrayof binded objects, instead ofstd::initializer_listof binded objects.Something along the lines
and you would call it like:
See a demo here
In C++20, using template lambda this can be however in one function.
See a demo here