3

I have this template class:

template<typename T, T F(const std::string&)>
struct Builder
{
  T operator()(const std::string& s) const { return F(s); }
  typedef T type;
};

since I need a class holding a function and the value returned by the function (since I need a reference to it).

As you can see I have two template parameters, but actually the first is redundant. Is is possible to remove it in some way? Template alias? Something better than a macro

Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141

1 Answers1

3

Return type T of the second template parameter must be defined before its first usage anyway (as the C++ rule states that any entity can be used only after its declaration), and the only way to declare is to use preceding type template parameter (as you did), so you cannot omit the first parameter.

tonso
  • 1,760
  • 1
  • 11
  • 19