I am implementing a search algorithm with heuristic function in c++ 20. I'm trying to constrain the function my algorithm can use with a concept like so:
template<typename SelfType, unsigned from, unsigned to>
concept Heuristic = requires(SelfType h, unsigned current)
{
{ h(current) } -> unsigned;
assert(h(to) == 0);
};
Then I can write something like:
template<unsigned from, unsigned to>
struct H
{
unsigned operator()(unsigned current)
{
return to - current + 100;
}
};
Of course the assert does not work and that is not a valid heuristic because here h(to) is 100. I want to make the compiler check in compile time that h(to) equals 0.