I\'m trying to create a variadic templated class which provides a method for each class in the typelist. An example is shown below which creates a print
method for
I don't like answering my own question but I've created the following solution from the comments here. It brings all print
functions into scope and allows for C++ overload resolution on all of the functions.
#include
#include
// Helper class providing a function call
template
class PrintHelper
{
public:
void print(const T& t) { std::cout << t << std::endl; }
};
// Provides a print method for each type listed
template
class Printer
{};
template
class Printer : public PrintHelper
{
public:
using PrintHelper::print;
};
template
class Printer: public PrintHelper, public Printer
{
public:
using PrintHelper::print;
using Printer::print;
};
int main()
{
Printer p;
p.print("Hello World"); // Not an ambiguous Call
}