The following works
#include <iostream>
template<typename A, typename B> double func1(B x, B y)
{
A a = 3.0f;
return a + x + y;
}
template<typename A, typename B> double func2()
{
B x = 5.0;
B y = 8.0;
return func1<float>(x, y);
}
int main()
{
std::cout << func2<float, double>() << "\n";
}
However, what if I would like func1 to be substituted with another similar function? One with the same number and type of arguments and template parameters. I tried template<template<... like below, and it didn't seem to work.
#include <iostream>
template<typename A, typename B> double func1(B x, B y)
{
A a = 3.0f;
return a + x + y;
}
template<template <typename, typename> typename func, class A, class B>
double func2()
{
B x = 5.0;
B y = 8.0;
return func<A, B>(x, y);
}
int main()
{
std::cout << func2<func1, float, double>() << "\n";
}
It would be nice if a pattern like the one above worked.
Even better if func, could be partially templatized and still deduce from the type of the arguments like
#include <iostream>
template<typename A, typename B> double func1(B x, B y)
{
A a = 3.0f;
return a + x + y;
}
template<template <typename, typename> typename func, class A, class B>
double func2()
{
B x = 5.0;
B y = 8.0;
return func<A>(x, y);
}
int main()
{
std::cout << func2<func1, float, double>() << "\n";
}
Any ideas on how to get the 2nd snippet to work?
Could you do so with template deduction as well? Could c++20 concepts do magic here?