I have a bunch of those classes that implement a generic call operator:
template<typename T = char>
struct match {
template<initer_of_type<T> IterT>
constexpr auto operator()(IterT iter) const -> std::optional<decltype(iter)> {
// ... function body
}
// ... some members
}
// ... more similar structs
in a class template, where the operator itself is also a template.
NOTE: I'm using here a concept that I made to accept any input iterator that returns the specific value type:
template<typename IterT, typename T>
concept initer_of_type =
std::input_iterator<IterT>
&& std::is_same_v<typename IterT::value_type, T>;
That way I can use the algorithm on any iterable Ts container...
I'd like to be able to hold an array of these objects, all of which have the same template parameter T but may be different classes. It seems like I cannot use neither plain inheritence nor type erasue (at least the way I know it) because the function is a template. Is there a good way to do this? Or am I looking for the wrong solution?