// Same as above, with a using directive for the std namespace. Actually it illustrates a bad use of a using directive. #include #include #include // abs #include "point.h" using namespace std; // In this variant, we do not qualify each name from the standard namespace with std:: // Illustration of alternative return type - best if return type depends on parameters. auto find_diagonal_points(vector points) -> vector{ vector res; for(auto p: points) if(abs(p.getx())==abs(p.gety())) res.push_back(p); return res; } void without_auto(){ int i{5}; vector points = {Point{1,1}, Point{1,2}, Point{-1,1}, Point{-2,2}}; vector diagonal_points = find_diagonal_points(points); for(Point p: diagonal_points) cout << p << endl; } void with_auto(){ auto i = 5; // initialize auto's with =, not {}. auto points = vector{{Point{1,1}, Point{1,2}, Point{-1,1}, Point{-2,2}}}; auto diagonal_points = find_diagonal_points(points); for(auto p: diagonal_points) cout << p << endl; } int main () { without_auto(); cout << endl; with_auto(); }