16.2.3. Trailing Return Types and Type Transformation

Image

Using an explicit template argument to represent a template function’s return type works well when we want to let the user determine the return type. In other cases, requiring an explicit template argument imposes a burden on the user with no compensating advantage. For example, we might want to write a function that takes a pair of iterators denoting a sequence and returns a reference to an element in the sequence:

template <typename It>??? &fcn(It beg, It end){    // process the range    return *beg;  // return a reference to an element from the range}

We don’t know the exact type we want ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.