#include
template
auto func(const T &value)
{
return F(value);
}
template
T myAbs(const T& val)
{
return std::abs(val);
}
struct myStruct
{
double m_val;
};
template
concept isStruct = requires(T & t)
{
t.m_val;
};
template
T myAbs(const T& val)
{
T result;
result.m_val = std::abs(val.m_val);
return result;
}
template
T indirectAbs(const T& val)
{
return myAbs(val);
}
int main()
{
double val1 = -1.0;
myStruct struct1{ -1.0 };
double val2 = myAbs(val1);
myStruct struct2 = myAbs(struct1);
//The line below won't compile as decltype cannot deduce the correct function based on the concept
//myStruct struct3 = func(struct1);
//Instead I have to use an extra level of indirection as the upperAbs function can find the correct function
myStruct struct3 = func(struct1);
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79756704/decltype-not-able-to-pick-a-template-function-based-on-its-concept[/url]