#include "stdio.h"
#include <iostream>
#include <string>
#include <chrono>
#include <vector>
#include <map>
#include <algorithm>

using namespace std::chrono;
using namespace std;

// create vector holding desired ordering
vector<string> order({ "a", "d", "i", "n", "ns", "ne", "vl", "rr" });

// create sort function for vector of pairs
bool comparator1(const pair<string, string> &s1, const pair<string, string> &s2) {
	// find() - it.begin() gives you the index number. 
	int a = find(order.begin(), order.end(), s1.first) - order.begin();
	int b = find(order.begin(), order.end(), s2.first) - order.begin();
	return a < b; // lower index < higher index
};



bool comparator2(const pair<string, string> &s1, const pair<string, string> &s2) {
	// find() - it.begin() gives you the index number. 
	auto a = std::make_tuple(s1.first =="a", s1.first =="d", s1.first =="i", s1.first =="n", s1.first =="ns", s1.first =="ne", s1.first =="vl", s1.first =="rr");
	auto b = std::make_tuple(s2.first =="a", s2.first =="d", s2.first =="i", s2.first =="n", s2.first =="ns", s2.first =="ne", s2.first =="vl", s2.first =="rr");
	return a < b; // lower index < higher index
};



vector<pair<string, string>> vp ={ { "a","legato" },{ "vl","3" },{ "i", "3" },{ "rr","2" } };

void sortWithVector() {
	sort(vp.begin(), vp.end(), comparator1);
}

void sortWithTuple() {
	sort(vp.begin(), vp.end(), comparator2);
}

int main()
{
	high_resolution_clock::time_point t1;
	high_resolution_clock::time_point t2;
	double duration;
	
	
	
	
	t1 = high_resolution_clock::now();
	
	for (int i=0; i < 10000; ++i) sortWithVector();
	
	t2 = high_resolution_clock::now();
	duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
	cout << duration/1000.0  << "ms" << endl;
	
	
	
	
	t1 = high_resolution_clock::now();
	
	for (int i=0; i < 10000; ++i) sortWithTuple();
	
	t2 = high_resolution_clock::now();
    duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
    cout << duration/1000.0  << "ms" << endl;

    return 0;
}