I have used following similar pieces of code for many years. However, I
just found out that the document says that copy should be used to copy items
to an empty container. Is copying to an empty container serious? Please
advise.
vector<int> v;
....
set<int> s;
copy(v.begin(), v.end(), inserter(s, s.begin())); // copy v to an empty
container s
Thanks.
JD
I don't see the problem there, even though I would usually just use:
s.insert(v.begin(), v.end());
There are other situation where using an inserter iterator and an
algorithm like std::copy can be useful, though.
Think of it as inserting into an empty container. That's what the insert
iterator does.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)