On Apr 29, 1:38*pm, Scott Meyers <NeverR...@aristeia.com> wrote:
> 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):
>
> > 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
I am not too sure but I happened to read on emplace proposals
recently.
From
http://www.open-std.org/jtc1/sc22/wg...2008/n2680.pdf
, the author says,
"However, variadic templates provide no way of supplying two argument
lists (such a facility
would require a new syntax at the call site). But since the key_type
of a map is in practice much
less likely to require in-place construction, I believe that the
common (albeit asymmetrical) use N2642=08-0152 2 2008-05-19
case of a copy (or move) constructed key_type with an in-place
constructed mapped_type is
well worth supporting. "
So I guess the key is the first argument and being copied/moved, and
the value is in-place constructed?