Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail From: Daniel James Newsgroups: comp.std.c++ Subject: Reserve(n) for unordered containers reserves for n-1 elements. Date: Thu, 3 May 2012 11:06:40 -0700 (PDT) Organization: http://groups.google.com Lines: 20 Sender: std-cpp-request@vandevoorde.com Approved: austern@google.com Message-ID: <23057638.2760.1335985330955.JavaMail.geo-discussion-forums@vbxz8> NNTP-Posting-Host: 4BI2cH1iFNvH8ZRMaFgbPCFsI/hXgwdLeusHLX/MQck= Content-Type: text/plain; charset=ISO-8859-1 X-Trace: news.albasani.net jDd2DECfgH7drNKGgdbrMANps1BQcEJIvvTkarXmjcRfwX1rg0im3lQ30q8ZmtOPv/kRjWXNZCz+YtadZAXBIg== X-Complaints-To: abuse@albasani.net NNTP-Posting-Date: Thu, 3 May 2012 18:06:44 +0000 (UTC) X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:JhTUpClHMMEEZXoZiUvJl5qz9W4= X-Original-Date: Wed, 2 May 2012 12:02:10 -0700 (PDT) Xref: csiph.com comp.std.c++:506 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 ]