I am trying to create a template function in C++ like:
template<typename IteratorType>
double evaluate(const IteratorType &rBegin, const IteratorType &rEnd,
double(*function)( const decltype( *IteratorType ) &rObject )) // error, typename not allowed
// I'm unsure if I need to put the reference there, not part of the problem.
{
// ...
}
// not my actual code, just to show an example.
Though this does not work since I need an instance of a class/struct to call a non-static method,
which I can't do since it's in a function.
After googling around a bit I found this solution:
double(*function)( const typename std::iterator_traits<IteratorType>::value_type &rObject )
Though as you can see this gets clumsy to use (and is a pain to change), especially when you are trying to create multiple overloads. This also did not seem to work for my iterators, so after a while I realized this:
double(*function)( const typename IteratorType::value_type &rObject)
would be the best solution.
In the end I realized there was no guarantee for "IteratorType" to have value_type defined as the type of the value, and that pointers are a thing.
Is there any way for me to get away with something along the lines of
double(*function)( const decltype(*IteratorType) &robject)
?