Re: std::set has no assign
On Jul 4, 1:33 am, "Andrew Koenig" <a...@acm.org> wrote:
<gast...@hotmail.com> wrote in message
news:1182430216.130153.193690@p77g2000hsh.googlegroups.com...
probably already asked a lot, but I see that there is no assign in
std::set. The std::set has the templated iterator constructor so it
seems possible.
Well, it's a bit hard to define assign for an associative container because
the elements are intended to be immutable once added. So whatever calling
assign on a set might do, it had better not change the values of the
elements assigned to.
std::vector<>'s assign(first, last) has the effect of :
erase(begin(), end());
insert(begin(), first, last);
so it is not changing the values of the elements of the vector<>. The
same behaviour could be had for the assign of set<>. It erases the
elements and then inserts it, this insert will have the same behaviour
as that of the constructor that takes in a range (there exists insert
for set as well). I could not convince myself why it really does not
exist?
It would have had helped templated parameterized by container types
that intend to exploit assign() interface. That is still workable with
a combination of erase() and a subsequent insert() but if it exists
for vector<>, then why not for set<>?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]