/*
 * Marc Groenewegen, 2023
 */

#include <iostream>
#include <set>
#include <iterator>


int main()
{
std::set<std::string> myset;
std::set<std::string>::iterator pos;

  myset.insert("joepie");
  myset.insert("dit");
  myset.insert("programmeerwerk");
  myset.insert("is");
  myset.insert("leuk");
  myset.insert("wel");
  myset.insert("leuk");
  myset.insert("dit");

  std::cout << "Size: " << myset.size() << std::endl;
  std::cout << "Question: does the size match your expectations?" << std::endl;

  std::cout << std::endl << "Set's (ordered) contents: " << std::endl;
  pos=myset.begin();
  while(pos != myset.end())
  {
    std::cout << *pos << std::endl;
    pos++;
  }
  std::cout << std::endl;

  std::string word2find = "is";
  pos = myset.find(word2find);

  if(pos == myset.end()){
    std::cout << word2find << " not found" << std::endl;
  }
  else {
    std::cout << "Found \"" << word2find << "\"" << std::endl;
    std::cout << "Erasing this word" << std::endl;
    myset.erase(pos);

    // showing new contents after erasing an element
    std::cout << "New size: " << myset.size() << std::endl;

    // A set can not be re-sorted. The order of elements is determined at
    // the time of insertion of new elements. We can however loop over the
    // set from beginning to end.
    std::cout << std::endl << "Set's contents: " << std::endl;
    pos=myset.begin();
    while(pos != myset.end())
    {
      std::cout << *pos << std::endl;
      pos++;
    }
    std::cout << std::endl;

    // *pos = "nana"; // This is not allowed because it could break the sort order
  } // else

  return 0;
}
