"mimi" <cainiaodelixiang@gmail.comwrote in message
news:1173170494.977849.121860@p10g2000cwp.googlegr oups.com...
On 3月6日, 下午1时22分, Amit Bhatia <abha...@nospam.nospam.comwrote:
Quote:
P.J. Plauger wrote:
Quote:
"Thomas Tutone" <Thomas8675...@yahoo.comwrote in message
news:1173139381.616960.33260@j27g2000cwj.googlegro ups.com...
>
Quote:
Quote:
On Mar 5, 5:51 pm, Amit Bhatia <amit.bhatia.nos...@nospam.comwrote:
>
Quote:
Quote:
> I was wondering if I have a hash_set, can I modify its elements using
>an
>iterator: given the fact that the changes I make will not change the
>position or the key of the object that the iterator points to?
>
Quote:
Quote:
>Or do I need to necessarily use hash_map ?
Standard C++ doesn't have anything called a hash_set or hash_map -
those are extensions that some implementations have added. The next
version of C++ will have what is now designated as
std::tr1::unordered_set and std::tr1::unordered_map, which fill a
similar purpose, but have slightly different syntax. For more
information about unordered_set and unordered_map, take a look at
section 6.3 of this:
>
>
Quote:
Quote:
Or take a look at Pete Becker's new book on tr1.
>
Quote:
That's the officious answer. The useful answer is that hash_set
is just like (unordered_)set in this regard -- if you do contrive to
alter the stored key you risk destroying the integrity of the
container. Erase the old value and insert the new value instead.
>
Thanks. But let's say each object in the hash_set has a boolean, and a
vector of integers, whose value(s) do not affect the key for sure (I
supply the hash function): then won't this method of copying-erasing-
changing-inserting result in substantial speed slow up? I just might
want to change boolean variable in the class object and still I have to
copy the whole thing first..
>
thanks,
--a.- 隐藏被引用文字 -
>
- 显示引用的文字 -
Maybe you could take the boolean value out and associate it with with
each object by using hash_map.
[pjp] Right. If your "key" really has components that don't participate in
the
ordering, then you really have a map masquerading as a set. And if
on top of that the non-ordering components are heavyweight, then
you're really being perverse in not separating them out as the
"mapped" part of a (key, mapped) pair stored in a map.
Or you could just use const_cast, which is evil.
[pjp] Indeed.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com