I really don't understand why C ++ 20 provides such a function. I think this is redundant , yes, I'm sure I'm wrong, but I need someone to indicate why I am wrong and how to use this function gracefully. Here is an example:
template<typename T> concept LessCompareable=requires(const T& lhs, const T& rhs) { {lhs<rhs}->bool; };
Now I have defined the concept. Then I will restrict the function template as follows: (well, let's call it comp, in fact it is exactly the same as std::min )
template<typename T> const T& comp(const T& a , const T& b) requires LessCompareable<T> {return a<b?a:b;}
So the problem is that you call it like
std::thread a,b; cout<<comp(a,b);
Error Execution Error
but if we do not use the restriction, CE will happen too.
So, this puzzles me, both of them have CE, then why should I use restrictions?
source share