0

Basically I want my vector to be unique and not in order as that helps me in calculating distance and determine the best route

This is the instance

vector<tuple<int, int>> child_chromosome;

this is what I have tried

 unordered_set<vector<tuple<int,int>>> s(child_chromosome.begin(), child_chromosome.end());
 child_chromosome.assign(s.begin(), s.end());

This doesn't work giving error when debug

Error   C2280   'std::_Uhash_compare<_Kty,_Hasher,_Keyeq>::_Uhash_compare(const std::_Uhash_compare<_Kty,_Hasher,_Keyeq> &)': attempting to reference a deleted function    GenAlgoRealLife C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\unordered_set 49

Also tried a solution from Scala: Remove duplicated integers from Vector( tuples(Int,Int) , ...) but to avail as its using a different language & no such attributes(groupBy,filter) exits in C++

Moin ud-din
  • 76
  • 1
  • 3
  • 5
    If you try to verbalize what `unordered_set>>` means, in plain English, using as simple words as possible, and whether this is what you're actually trying to do, then the problem should be fairly clear. – Sam Varshavchik Aug 03 '22 at 18:07
  • well what the `unordered_set<>` does is convert my vector into set and in set we can remove the duplicates without changing the order [link](https://www.techiedelight.com/remove-duplicates-vector-cpp/) I hope this helps you – Moin ud-din Aug 03 '22 at 19:23
  • 1
    What does `unordered_set>>` mean to you? It does not mean "convert my vector into a set". It means that this object is an unordered set, and the set contains vectors of tuples with two integers. That's what it means, in plain english. Additionally, "unordered" does not mean "the order is not changed". It means that all the contents in the set are in some random order that's completely unspecified, and can be anything. If you open your C++ textbook to the chapter that describes what unordered containers are, is there something there that led you to believe otherwise? – Sam Varshavchik Aug 03 '22 at 19:27
  • Which part of your C++ textbook or tutorial you interpreted to mean that in an unordered set, the order of its contents does not change in any way, from the order that the contents were added to the set? Can you briefly quote the passage that left such an impression? Something must've been misunderstood, here. – Sam Varshavchik Aug 03 '22 at 19:29
  • I'll be honest I haven't read any book and just a beginner also thanks for pointing this out – Moin ud-din Aug 03 '22 at 19:33
  • 3
    That's the problem. C++ is the most complicated and the hardest to learn general purpose programming language in the world today. It's just too complicated to be learned by watching random Youtube videos, doing silly coding puzzles, or running Google searches. A full, in-depth tutorial can only be found [in a good C++ textbook](https://stackoverflow.com/questions/388242/). Did wherever you learned about `unordered_set` from actually explain what "unordered" means, for sets or maps, in C++? C++ is just too complicated to be learned by asking one question at a time, that's just the way it is. – Sam Varshavchik Aug 03 '22 at 19:38

0 Answers0