	#include <algorithm>
	#include <functional>
	#include <iostream>
	#include <string>
	
	struct TeamStats {
		std::string name;
		float yards_per_game;
		int total_points;
	};
	
	using QuickSortPred = std::function<bool(const TeamStats&, const TeamStats&)>;
	
	template<typename I>
	void quickSort(I begin, I end, QuickSortPred predicate)
	{
		/// NOTE: This is NOT a complete quicksort, it's just to demonstrate
		/// the usage of predicate.

		std::sort(begin, end, predicate);	
	}
	
	int main() {
		std::vector<TeamStats> arr {
			{ "Red",   100, 30, },
			{ "Blue",  150, 10, },
			{ "Green", 200, 20, },
		};
	
		// approach one, store the lambda before hand
		auto sortByYards = [](const TeamStats& lhs, const TeamStats& rhs) -> bool {
			return lhs.yards_per_game < rhs.yards_per_game;
		};
		quickSort(arr.begin(), arr.end(), sortByYards);
		std::cout << "By yards:\n";
		for (auto& it : arr) {
			std::cout << it.yards_per_game << " " << it.name << "\n";
		}
		
		// approach two, write the lambda inline.
		quickSort(arr.begin(), arr.end(), [](const TeamStats& lhs, const TeamStats& rhs) -> bool {
			return lhs.total_points < rhs.total_points;
		});
		std::cout << "By points:\n";
		for (auto& it : arr) {
			std::cout << it.total_points << " " << it.name << "\n";
		}
	
		return 0;
	}