How to get the first element of a std::set
your code work well in VS2010, mybe you should update your vcc.
linello
Currently I'm scientific software developer with proficiency in C/C++ with their related technologies Boost, STL, Qt, Python, computer graphics, OpenGL, Mathematica, MatLab, Bash scripting, NI Labview, LATEX, CMake, CUDA.
Updated on June 03, 2020Comments
-
linello almost 4 years
I you all,
I found a strange bug in my software.
Inside a while loop where I remove elements from a std::set, I want always to take the first element until the container is empty:
std::set< int*> nodes; // Fill nodes for (int i=0; i<10;i++) nodes.insert(new int); // while (!nodes.empty()) { int* pivot = (*nodes.begin()); // do some operation with pivot erasing some elements from nodes }
I found that implementing the first element this way works with gcc but not with MSVC, it crashes where I try to dereference the
(*nodes.begin())
iterator.Do the two implementation of std::set behave differently?
I would like to have a data structure with no differences of implementation, is it possible?
Probably I must change data structure for this kind of operations