Sets Equivalent in cpp

What is the equivalent cpp code for the below python code snippet.

1
2
3
  //Here the left points is the list of objects.
  left_shapes = list(set(left_points))
  left_shapes.sort()

c++ has sets but they are not exactly what you think of from math (same as how vectors are not math vectors).
you can sort a c++ list without a set. What purpose does the set do for py? In c++ it could be used to remove duplicates, or other things, but it would be an unnecessary data copy from one container to another in most scenarios.
In c++ std::set exists. See:

http://www.cplusplus.com/reference/set/set/?kw=set

They are already sorted.
good point, you could just not have the list, and go directly to set. But it depends on what you are trying to do beyond the 2 lines.
Sets aren't ordered in python.

As Jonnin says, it depends what happens beyond those two lines. But you will have to define an ordering operation (which, given the names, might be non-trivial).
The purpose of sets here is to remove duplicates @jonnin
In the next step I am iterating the left_shapes and checking for the if condition. @lastchance
In the next step I am iterating the left_shapes and checking for the if condition.


I don't know what "checking for the if condition" means. Why not show us the next step rather than just describing what it does?

A C++ std::set will (1) get rid of duplicates and (2) order the elements. So, it looks like that's what you need.
What are left_shapes, and how are they ordered? There needs to be some sort of well-defined ordering between the shapes.
Last edited on
if you need to remove dupes, using a set up front and never fooling with the list sounds like a possible way to build it.
Topic archived. No new replies allowed.