Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel James <dnljms@gmail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Reserve(n) for unordered containers reserves for n-1 elements. |
| Date | 2012-05-03 11:06 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <23057638.2760.1335985330955.JavaMail.geo-discussion-forums@vbxz8> (permalink) |
Hello, When calling 'x.reserve(n)' for an unordered container I'd expect to be able to insert n elements without invalidating iterators. But as the standard is written, the guarantee only holds for n-1 elements. For a container with max_load_factor of 1, reserve(n) is equivalent to rehash(ceil(n/1)), which is rehash(n). rehash(n) requires that the bucket count is >= n, so it can be n. The rule is that insert shall not affect the validity of iterators if (N + n) < z * B. But for this case the two sides of the equation are equal, so insert can affect the validity of iterators. Is that a mistake? Daniel -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Next in thread | Find similar
Reserve(n) for unordered containers reserves for n-1 elements. Daniel James <dnljms@gmail.com> - 2012-05-03 11:06 -0700 Re: Reserve(n) for unordered containers reserves for n-1 elements. Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-05-04 11:24 -0700
csiph-web