Quantcast
Viewing all articles
Browse latest Browse all 7

Answer by Levi Morrison for C++14 Variable Templates: what is their purpose? Any usage example?

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.


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>