#include <iostream>
template<typename T, typename U>
decltype(T() + U()) add(T a, U b)
{
return a + b;
};
template<class T1, class T2>
decltype(T1() * T2()) f(T1 v1[], T2 v2[], size_t count) // Will not compile!
{
decltype(v1[0]*v2[0]) sum(0);
for(size_t i = 0; i<count; i++) sum += v1[i]*v2[i];
return sum;
};
int main()
{
int i = 9;
int ia[] = {1,2,3,4,5};
double da[] = {1.0,2.0,3.0,4.0,5.0};
double d = 2.0;
auto a = add<int, double>(i,d);
auto a2 = f<int,double>(ia,da, 5);
std::cout << a << std::endl;
std::cout << a2 << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgVT4KZGVjbHR5cGUoVCgpICsgVSgpKSBhZGQoVCBhLCBVIGIpCnsKICAgIHJldHVybiBhICsgYjsKfTsKCnRlbXBsYXRlPGNsYXNzIFQxLCBjbGFzcyBUMj4KZGVjbHR5cGUoVDEoKSAqIFQyKCkpIGYoVDEgdjFbXSwgVDIgdjJbXSwgc2l6ZV90IGNvdW50KSAvLyBXaWxsIG5vdCBjb21waWxlIQp7CiAgICBkZWNsdHlwZSh2MVswXSp2MlswXSkgc3VtKDApOwogICAgZm9yKHNpemVfdCBpID0gMDsgaTxjb3VudDsgaSsrKSBzdW0gKz0gdjFbaV0qdjJbaV07CiAgICByZXR1cm4gc3VtOwp9OwoKaW50IG1haW4oKQp7CiAgICBpbnQgaSA9IDk7CiAgICBpbnQgaWFbXSA9IHsxLDIsMyw0LDV9OwogICAgZG91YmxlIGRhW10gPSB7MS4wLDIuMCwzLjAsNC4wLDUuMH07CiAgICAKICAgIGRvdWJsZSBkID0gMi4wOwogICAgCiAgICBhdXRvIGEgPSBhZGQ8aW50LCBkb3VibGU+KGksZCk7CiAgICBhdXRvIGEyID0gZjxpbnQsZG91YmxlPihpYSxkYSwgNSk7CiAgICAKICAgIHN0ZDo6Y291dCA8PCBhIDw8IHN0ZDo6ZW5kbDsKICAgIHN0ZDo6Y291dCA8PCBhMiA8PCBzdGQ6OmVuZGw7Cn0=