I have a exercise in C++ Primer 6th:
Complete the program by supplying the
average_list()
function. It should be a template function, with the type parameter being used to specify the kind ofinitialized_list
template to be used as the function parameter and also to give the function return type.
I have no idea with it
Here is part of a short program:
int main() {
using namespace std;
// list of double deduced from list contents
auto q = average_list({15.4, 10.7, 9.0});
cout << q << endl;
// list of int deduced from list contents
cout << average_list({20, 30, 19, 17, 45, 38} ) << endl;
// forced list of double
auto ad = average_list<double>({'A', 70, 65.33});
cout << ad << endl;
}