/* Lecture Code 4.2
 *
 * Breaking a set's internal ordering by overwriting a specific
 * element.  This code will NOT compile in Xcode or g++, since
 * the g++ authors decided to disallow this behavior to avoid easy
 * sources of logical errors.
 */
#include <iostream>
#include <set>
using namespace std;

/* Constant: kNumValues
 * -------------------------------------------------
 * The number of elements to insert into the set.
 */
const size_t kNumValues = 10;

int main() {
	/* Create a set and populate it with values. */
	set<int> mySet;
	for(size_t i = 0; i < kNumValues; i++)
		mySet.insert(i); // Add i to the set

	/* Overwrite the value 5 in the set by clobbering it with
	 * the value 137.  This disrupts the internal ordering and
	 * causes future lookups to fail.
	 */
	*mySet.find(5) = 137;
	
	/* Counting from 0 to kNumValues, see what the set reports
	 * it contains.  This is platform-dependent, but on my system
	 * causes all values greater than or equal to five to appear
	 * to be missing.
	 */
	for (size_t i = 0; i < kNumValues; ++i)
		cout << i << ": " << (mySet.count(i)? "found" : "not found") << endl;
}