S
Scott Meyers
I'm having another of those days where nothing makes sense, sigh.
C++0x's unordered_map supports emplacement via this member function
(from the FDIS):
template <class... Args>
pair<iterator, bool> emplace(Args&&... args);
Now, somehow emplace's implementation has to figure out which elements
of args correspond to the unordered_map's key and which to the mapped
data. That is, given an unordered_map<K, T> named "um" and a call to
emplace as follows,
um.emplace(foo, bar, baz, wuz, hmmm, er, ouch);
emplace has to figure out which of those arguments correspond to K and
which to T. How does it do that? The only description I can find of
what's supposed to happen is in table 103 of the FDIS, where I'm told
that, given an unordered_map of type X, a call of the form
um.emplace(args) has the following semantics. Note that in what
follows, T is the mapped type for the container (per 23.2.5/3):
If all the data in args is used to construct an object of type T, how
can emplace figure out what the key is supposed to be?
Thanks,
Scott
C++0x's unordered_map supports emplacement via this member function
(from the FDIS):
template <class... Args>
pair<iterator, bool> emplace(Args&&... args);
Now, somehow emplace's implementation has to figure out which elements
of args correspond to the unordered_map's key and which to the mapped
data. That is, given an unordered_map<K, T> named "um" and a call to
emplace as follows,
um.emplace(foo, bar, baz, wuz, hmmm, er, ouch);
emplace has to figure out which of those arguments correspond to K and
which to T. How does it do that? The only description I can find of
what's supposed to happen is in table 103 of the FDIS, where I'm told
that, given an unordered_map of type X, a call of the form
um.emplace(args) has the following semantics. Note that in what
follows, T is the mapped type for the container (per 23.2.5/3):
Requires: T shall be
EmplaceConstructible into X
from args.
Effects: Inserts a T object t
constructed with
std::forward<Args>(args)...
if and only if there is no
element in the container with
key equivalent to the key of t.
If all the data in args is used to construct an object of type T, how
can emplace figure out what the key is supposed to be?
Thanks,
Scott