#include <iostream>
#include <vector>
#include <algorithm>

struct element_t {
    int val;
    bool visited;
};

bool cmp(const element_t& lhs, const element_t& rhs)
{
    if (!lhs.visited && !rhs.visited) return (lhs.val < rhs.val);
    return lhs.visited ? rhs.visited : true;

	/* alternatively:
    return (lhs.visited || rhs.visited)
        ? rhs.visited
        : (lhs.val < rhs.val);
	*/

	/* alternatively:
	return (!lhs.visited) && (rhs.visited || lhs.val < rhs.val);
	*/
}

int main()
{
	std::vector<element_t> vct_priority{
		{1,true},
		{0,true},
		{1,false},
		{0,true},
		{2,false},
		{2147483647,false},
		{2147483647,false},
		{0,true},
		{1,false},
		{0,true},
		{2,false},
		{2147483647,false},
		{1,false}
	};

	do
	{
		auto it = std::min_element(std::begin(vct_priority), std::end(vct_priority), cmp);
		if (it == std::end(vct_priority) || it->visited) break;
		auto indx_smallest = std::distance(std::begin(vct_priority), it);
		std::cout << "index " << indx_smallest << ", value " << it->val << std::endl;
		it->visited = true;
	}
	while (true);

	std::cout << "done" << std::endl;
	return 0;
}