Another practical example for C++14's variable templates is when you need a function for passing something into std::accumulate
:
template<typename T>T const & (*maxer) (T const &, T const &) = std::max<T>;std::accumulate(some.begin(), some.end(), initial, maxer<float>);
Note that using std::max<T>
is insufficient because it can't deduce the exact signature. In this particular example you can use max_element
instead, but the point is that there is a whole class of functions that share this behavior.