Re: std::set has no assign
On 3 jul, 22:33, "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.
Yes, but what's the difference with insert and the set's overloaded
constructor in which one can fill it with [begin, end> from an other
container?
one can fill a set with ctor call, but not assign:
#include <vector>
#include <set>
#include <boost/assign/list_of.hpp>
void f()
{
std::vector<int> v = boost::assign::list_of(3)(1)(2);
std::set<int> intSet1(v.begin(), v.end());
std::set<int> intSet2;
//does not exist
//intSet2.assign(v.begin(), v.end());
intSet2 = std::set<int>(v.begin(), v.end());
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]