Let's imagine I have some complicated templated function and I want to test that it works as expected. In particular that when invoked with certain arguments that type of function is determined only by first argument. For example:
template<typename T>
bool less(const T& x, const std::type_identity_t<T>& y){
return x < y;
}
Here I would like to check something (with static_assert
or some test framework expect) that only first argument determines the signature of the function, something like:
std::is_same_v<decltype(less(short{1}, long{2})) , decltype(less(short{1}, double{2}))>;
But obviously this does not work since decltype will give me the result of function invocation, not the type of the function that is instantiated when I give it arguments I gave it.
Is there a way to do this(assume I can not modify the function, e.g. make it a functor with typedefed T or change it any other way)?
I tried searching for this, failed, I guess somebody asked this already but I could not find the question.
note: I know about testing behaviors, not implementation. Example is just tiny example, not something realistic.