Kompilator wyrzuca błędy:
main.cpp:4:42: error: no template named 'conditional_t' in namespace 'std'
main.cpp:4:61: error: no member named 'is_floating_point_v' in namespace 'std'
a chodzi konkretnie o szablon funkcji,która ma zwrócić typ zależny od wyniku dodawania dwóch liczb.
#include <iostream>
#include <type_traits>
template <class T,class R,class I = std::conditional_t<std::is_floating_point_v<T>,T,R>>
I sum(T x,R y)
{
return x+y;
}
int main(int argc, char *argv[])
{
int a = 20;
double b = 2.5;
std::cout<<sum(a,b)<<std::endl;
return 0;
}