summaryrefslogtreecommitdiffstats
path: root/styleguide/c++/c++11.html
diff options
context:
space:
mode:
authorpkasting <pkasting@chromium.org>2016-02-04 14:14:36 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-04 22:16:05 +0000
commit53121c429fda1499dfd68ae9ac27c4c51de16aa0 (patch)
tree0d2a39c4296d6a28ce883b8a1b50085314b1afd5 /styleguide/c++/c++11.html
parentb61d4dee1b0e98e2b5c0fba66c5ad4b1335c02fe (diff)
downloadchromium_src-53121c429fda1499dfd68ae9ac27c4c51de16aa0.zip
chromium_src-53121c429fda1499dfd68ae9ac27c4c51de16aa0.tar.gz
chromium_src-53121c429fda1499dfd68ae9ac27c4c51de16aa0.tar.bz2
Allow emplacement methods for containers, with some cautions.
BUG=none TEST=none Review URL: https://codereview.chromium.org/1664943003 Cr-Commit-Position: refs/heads/master@{#373637}
Diffstat (limited to 'styleguide/c++/c++11.html')
-rw-r--r--styleguide/c++/c++11.html19
1 files changed, 8 insertions, 11 deletions
diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html
index 8a6ea1d..cccae2e 100644
--- a/styleguide/c++/c++11.html
+++ b/styleguide/c++/c++11.html
@@ -383,6 +383,14 @@ std::end</a></td>
</tr>
<tr>
+<td>Emplacement methods for containers</td>
+<td><code>emplace()</code>, <code>emplace_back()</code>, <code>emplace_front()</code>, <code>emplace_hint()</code></td>
+<td>Constructs elements directly within a container without a copy or a move. Less verbose than <code>push_back()</code> due to not naming the type being constructed.</td>
+<td>E.g. <a href="http://en.cppreference.com/w/cpp/container/vector/emplace_back">std::vector::emplace_back</a></td>
+<td><code>std::map::emplace()</code> is not yet available on all libstdc++ versions we support. When using emplacement for performance reasons, your type should probably be movable (since e.g. a vector of it might be resized); given a movable type, then, consider whether you really need to avoid the move done by <code>push_back()</code>. For readability concerns, treat like <code>auto</code>; sometimes the brevity over <code>push_back()</code> is a win, sometimes a loss. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/m3cblzEta7A">Discussion thread</a></td>
+</tr>
+
+<tr>
<td>Forwarding references</td>
<td><code>std::forward()</code></td>
<td>Perfectly forwards arguments (including rvalues)</td>
@@ -835,17 +843,6 @@ the <code>&lt;complex&gt;</code> library.</td>
</tr>
<tr>
-<td>Construct Elements in Containers</td>
-<td><code>emplace()</code>,<code>emplace_back()</code>,
-<code>emplace_front()</code>, <code>emplace_hint()</code></td>
-<td>Constructs elements directly within a container without a copy
-or a move</td>
-<td>TODO: documentation link</td>
-<td>Use where element construction within a container
-is needed.</td>
-</tr>
-
-<tr>
<td>Container Compaction Functions</td>
<td><code>std::vector::shrink_to_fit()</code>,
<code>std::deque::shrink_to_fit()</code>, and