/* Lecture Code 8.0
 *
 * Code demonstrating the boost::lambda library (for creating
 * anonymous functions) and the BOOST_FOREACH macro (for
 * traversing containers concisely).
 */

#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <vector>
#include <boost/foreach.hpp>
#include <boost/lambda/lambda.hpp>
using namespace std;
using namespace boost::lambda;
using namespace boost;

const size_t kNumInts = 20;

int main() {
	/* Seed the randomizer. */
	srand((unsigned int)time(NULL));

	/* Generate a vector of kNumInts random values. */
	vector<int> random(kNumInts);
	generate(random.begin(), random.end(), rand);

	/* Sort entries by the last digit. */
	sort(random.begin(), random.end(), _1 % 10 < _2 % 10);

	/* Print everything out. */
	BOOST_FOREACH(int x, random)
		cout << setw(5) << x << endl;
	return 0;
}