jeudi 15 avril 2021

Use std::set with input order preserved

I would love to use std::set to store integers that have to be unique, but I don't want them to be sorted (e.g. I need the order of input to the set preserved)

For example:

set<int> exampleSet;
exampleSet.insert(5);
exampleSet.insert(2);
exampleSet.insert(10);
exampleSet.insert(0);

The set will now contain

{0,2,5,10}

I would like it to be in original order so

{5,2,10,0}

How do I achieve this?

Aucun commentaire:

Enregistrer un commentaire