How many elements are we talking about?
I did a short test with 10,000,000 integers (prepared in a vector) and entered them in three different ways into a set.
Prepare input:
std::vector<int> input; for(int i = 0; i < 10*1000*1000; ++i) { input.push_back(i); }
Insert into the specified element by element with insert:Vacation: 2.4 seconds / Debugging: 110.8 seconds
std::set<int> mySet; std::for_each(input.cbegin(), input.cend(), [&mySet] (int value) { mySet.insert(value); });
Paste into a set using insert(itBegin, itEnd) :Release: 0.9 seconds / Debug: 47.5 seconds
std::set<int> mySet; mySet.insert(input.cbegin(), input.cend());
Thus, the insert can be greatly accelerated, but even the slow path should be far from a few minutes.
EDIT:I did a test with debug-mode, meanwhile - wow - I know debugging performance, but it is more than I thought. With 50,000,000 items in debug mode, there is a poor distribution, so I updated the message to 10,000,000 items and showed the time to release and debug the assembly.
You can see the huge differences here - 50 times with a faster solution.
In addition, the quick solution ( insert(itBegin, itEnd) ) seems linear in relation to the number of elements (with preliminary data!). The previus test had five times more elements, and the insertion time decreased from 4.6 to 0.9 - about five times.