Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'                decltype/dt3.cc - Another sample use of decltype in a function template: container example.Lecture 2 - slide 24 : 29
Program 3

// Illustrates that the return type of f may depend on the 'element type' of the container, more precisely by the type of c[i].
// For some container types, such as vector<bool>, the element type may be non-obvious.
// Compiles with g++ -c dt3.cc -std=c++11 
// The example is adapted from item 3 of Effective Modern C++.

template<typename Container, typename Index>
auto f(Container& c, Index i) -> decltype(c[i]){
  //...
}