blob: deffadab89e4908606d59020c11c0f436f9b3383 [file] [log] [blame]
Nico Weber019d40f2014-09-23 20:21:591<!DOCTYPE html>
2<!--
3Copyright 2014 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7<html>
8<head>
9<meta charset="utf-8">
bratell85e14ac2014-12-17 17:26:3810<title>C++11 use in Chromium</title>
Nico Weber019d40f2014-09-23 20:21:5911<link rel="stylesheet" href="c++11.css">
12<style>
13table tbody tr td:first-child {
14 font-weight: bold;
15 font-size: 110%;
16}
17</style>
18</head>
19<body>
20<div id="content">
21<h1>C++11 use in Chromium</h1>
22
23<p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium
24checkout.</i></p>
25
26<p>This document summarizes the features of C++11 (both in the language itself
27and in enhancements to the Standard Library) and describes which features are
28allowed in Chromium and contains pointers to more detailed information. The
29Guide applies to Chromium and its subprojects. Subprojects can choose to be
30more restrictive if they need to compile on more toolchains than Chromium.</p>
31
brettw196290a2016-07-07 03:52:1632<p>This page comprises part of the more general
33<a href="https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md">Chromium C++ style guide</a>.</p>
34
Nico Weber019d40f2014-09-23 20:21:5935<p>You can propose to make a feature available or to ban a
Nico Weberc8eb8ca2015-11-11 00:23:3436feature by sending an email to <a
37href="https://groups.google.com/a/chromium.org/forum/#!forum/cxx">[email protected]</a>.
38Ideally include a short blurb on what the feature is, and why you think it
pkasting07c0959a2016-04-14 22:16:4339should or should not be allowed. Ideally, the list will arrive at some
brettw196290a2016-07-07 03:52:1640consensus and you can request review for a change to this file. If
danakj4fd49fe42015-11-18 20:54:1641there's no consensus, <code>src/styleguide/c++/OWNERS</code> get to decide --
Nico Weberc8eb8ca2015-11-11 00:23:3442for divisive features, we expect the decision to be to not use the feature yet
43and possibly discuss it again a few months later, when we have more experience
44with the language.</p>
Nico Weber019d40f2014-09-23 20:21:5945
danakj4fd49fe42015-11-18 20:54:1646<h2>Table of Contents</h2>
47<ol class="toc">
48<li>Allowed Features<ol>
49 <li><a href="#core-whitelist">Language</a></li>
50 <li><a href="#library-whitelist">Library</a></li>
51</ol></li>
52<li>Banned Features<ol>
53 <li><a href="#core-blacklist">Language</a></li>
54 <li><a href="#library-blacklist">Library</a></li>
55</ol></li>
56<li>To Be Discussed<ol>
57 <li><a href="#core-review">Language</a></li>
58 <li><a href="#library-review">Library</a></li>
59</ol></li>
60</ol>
61
62<h2 id="whitelist"><a name="core-whitelist"></a>C++11 Allowed Features</h2>
Nico Weber019d40f2014-09-23 20:21:5963
64<p>The following features are currently allowed.</p>
65
66<table id="whitelist_lang_list" class="unlined striped">
67<tbody>
68
69<tr>
70<th style='width:220px;'>Feature</th>
71<th style='width:260px;'>Snippet</th>
72<th style='width:240px;'>Description</th>
73<th style='width:240px;'>Documentation Link</th>
74<th style='width:240px;'>Notes and Discussion Thread</th>
75</tr>
76
77<tr>
pkastingf5279482016-07-27 02:18:2078<td>__func__ Local Variable</td>
79<td><code>__func__</code></td>
80<td>Provides a local variable containing the name of the enclosing function</td>
pkasting7f0693b32016-10-31 20:27:5081<td><a href="http://en.cppreference.com/w/cpp/language/function#func">__func__</a></td>
pkastingf5279482016-07-27 02:18:2082<td>Use instead of the non-standard <code>__FUNCTION__</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ojGfcgSDzHM">Discussion thread</a></td>
83</tr>
84
85<tr>
Nico Weber019d40f2014-09-23 20:21:5986<td>Angle Bracket Parsing in Templates</td>
pkasting07c0959a2016-04-14 22:16:4387<td><code>&gt;&gt;</code> for <code>&gt; &gt;</code>, <code>&lt;::</code> for <code>&lt; ::</code></td>
Nico Weber019d40f2014-09-23 20:21:5988<td>More intuitive parsing of template parameters</td>
pkasting7f0693b32016-10-31 20:27:5089<td><a href="http://stackoverflow.com/questions/15785496/c-templates-angle-brackets-pitfall-what-is-the-c11-fix">C++ templates angle brackets pitfall</a></td>
Nico Weber019d40f2014-09-23 20:21:5990<td>Recommended to increase readability. Approved without discussion.</td>
91</tr>
92
93<tr>
ericrk491cd202015-12-01 01:09:1694<td>Arrays</td>
95<td><code>std::array</code></td>
96<td>A fixed-size replacement for built-in arrays, with STL support</td>
pkasting07c0959a2016-04-14 22:16:4397<td><a href="http://en.cppreference.com/w/cpp/container/array">std::array</a></td>
ericrk491cd202015-12-01 01:09:1698<td>Useful in performance-critical situations, with small, fixed-size arrays. In most cases, consider std::vector instead. std::vector is cheaper to std::move and is more widely used. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/pVRQCRWHEU8">Discussion thread</a>.</td>
99</tr>
100
101<tr>
Nico Weber3537d872014-09-25 19:10:04102<td>Automatic Types</td>
103<td><code>auto</code></td>
104<td>Automatic type deduction</td>
pkasting07c0959a2016-04-14 22:16:43105<td><a href="http://en.cppreference.com/w/cpp/language/auto">auto specifier</a></td>
106<td><a href="https://google.github.io/styleguide/cppguide.html#auto">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5-Bt3BJzAo0">Another discussion thread</a>.</td>
Nico Weber3537d872014-09-25 19:10:04107</tr>
108
109<tr>
pkastingce246fa2016-04-14 17:54:08110<td>Constant Expressions</td>
111<td><code>constexpr</code></td>
112<td>Compile-time constant expressions</td>
113<td><a href="http://en.cppreference.com/w/cpp/language/constexpr">constexpr specifier</a></td>
114<td>Prefer to <code>const</code> for variables where possible. Use cautiously on functions. Don't go out of the way to convert existing code. <a href="https://google.github.io/styleguide/cppguide.html#Use_of_constexpr">Google Style Guide</a></td>
115</tr>
116
117<tr>
thakis12bfc742014-10-28 04:37:49118<td>Declared Type Accessor</td>
119<td><code>decltype(<i>expression</i>)</code></td>
pkasting07c0959a2016-04-14 22:16:43120<td>Provides a means to determine the type of an expression at compile-time, useful most often in templates.</td>
121<td><a href="http://en.cppreference.com/w/cpp/language/decltype">decltype specifier</a></td>
thakis12bfc742014-10-28 04:37:49122<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/_zoNvZd_dSo">Discussion thread</a></td>
123</tr>
124
125<tr>
mdempsky2319bef2014-11-07 05:25:12126<td>Default Function Creation</td>
127<td><code><i>Function</i>(<i>arguments</i>) = default;</code></td>
pkasting07c0959a2016-04-14 22:16:43128<td>Instructs the compiler to generate a default version of the indicated function</td>
129<td><a href="http://stackoverflow.com/questions/823935/whats-the-point-in-defaulting-functions-in-c11">What's the point in defaulting functions in C++11?</a></td>
130<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/qgU4mh_MpGA">Discussion thread</a></td>
mdempsky2319bef2014-11-07 05:25:12131</tr>
132
133<tr>
vmpstrfcdc338e2015-12-09 19:51:08134<td>Default Function Template Arguments</td>
pkasting07c0959a2016-04-14 22:16:43135<td><code>template &lt;typename T = <i>type</i>&gt;<br />
136<i>type</i> <i>Function</i>(T <i>var</i>) {}</code></td>
vmpstrfcdc338e2015-12-09 19:51:08137<td>Allow function templates, like classes, to have default arguments</td>
pkasting07c0959a2016-04-14 22:16:43138<td><a href="http://stackoverflow.com/questions/2447458/default-template-arguments-for-function-templates">Default Template Arguments for Function Templates</a></td>
vmpstrfcdc338e2015-12-09 19:51:08139<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/9KtaAsome-o">Discussion thread</a></td>
140</tr>
141
142<tr>
andersr127772e2014-11-07 17:02:52143<td>Delegated Constructors</td>
pkasting07c0959a2016-04-14 22:16:43144<td><code>Class() : Class(0) {}<br />
145Class(<i>type</i> <i>var</i>) : Class(<i>var</i>, 0) {}</code></td>
andersr127772e2014-11-07 17:02:52146<td>Allow overloaded constructors to use common initialization code</td>
pkasting07c0959a2016-04-14 22:16:43147<td><a href="https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/introduction_to_the_c_11_feature_delegating_constructors?lang=en">Introduction to the C++11 feature: delegating constructors</a></td>
andersr127772e2014-11-07 17:02:52148<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/0zVA8Ctx3Xo">Discussion thread</a></td>
149</tr>
150
151<tr>
thakisb8fbe312014-10-29 01:30:42152<td>Enumerated Type Classes and Enum Bases</td>
pkasting07c0959a2016-04-14 22:16:43153<td><code>enum class <i>classname</i><br />
154enum class <i>classname</i> : <i>base-type</i><br />
155enum <i>enumname</i> : <i>base-type</i></code></td>
156<td>Provide enums as full classes, with no implicit conversion to booleans or integers. Provide an explicit underlying type for enum classes and regular enums.</td>
pkasting7f0693b32016-10-31 20:27:50157<td><a href="http://en.cppreference.com/w/cpp/language/enum">enumeration declaration</a></td>
pkasting07c0959a2016-04-14 22:16:43158<td>Enum classes are still enums and follow enum naming rules (which means SHOUTY_CASE in the <a href="http://www.chromium.org/developers/coding-style#Naming">Chromium Style Guide</a>). <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Q5WmkAImanc">Discussion thread</a></td>
mdempsky4f2d4102014-10-20 17:31:27159</tr>
160
161<tr>
jbromane18d31482016-04-13 18:06:47162<td>Explicit Conversion Operators</td>
pkasting07c0959a2016-04-14 22:16:43163<td><code>explicit operator <i>type</i>() { ... }</code></td>
jbromane18d31482016-04-13 18:06:47164<td>Allows conversion operators that cannot be implicitly invoked</td>
pkasting07c0959a2016-04-14 22:16:43165<td><a href="http://en.cppreference.com/w/cpp/language/explicit">explicit specifier</a></td>
jbromane18d31482016-04-13 18:06:47166<td>Prefer to the "safe bool" idiom. <a href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/zGF1SrQ-1HQ/BAiC12vwPeEJ">Discussion thread</a></td>
167</tr>
168
169<tr>
dcheng5f98d332014-09-24 22:12:10170<td>Final Specifier</td>
171<td><code>final</code></td>
172<td> Indicates that a class or function is final and cannot be overridden</td>
pkasting7f0693b32016-10-31 20:27:50173<td><a href="http://en.cppreference.com/w/cpp/language/final">final specifier</a></td>
pkasting07c0959a2016-04-14 22:16:43174<td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
dcheng5f98d332014-09-24 22:12:10175</tr>
176
177<tr>
mdempsky2319bef2014-11-07 05:25:12178<td>Function Suppression</td>
179<td><code><i>Function</i>(<i>arguments</i>) = delete;</code></td>
pkasting07c0959a2016-04-14 22:16:43180<td>Suppresses the implementation of a function, especially a synthetic function such as a copy constructor</td>
pkasting7f0693b32016-10-31 20:27:50181<td><a href="http://en.cppreference.com/w/cpp/language/function#Deleted_functions">Deleted functions</a></td>
mdempsky2319bef2014-11-07 05:25:12182<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/i1o7-RNRnMs">Discussion thread</a></td>
183</tr>
184
185<tr>
thakisa907c312014-11-04 23:38:06186<td>Lambda Expressions</td>
187<td><code>[<i>captures</i>](<i>params</i>) -&gt; <i>ret</i> { <i>body</i> }</code></td>
188<td>Anonymous functions</td>
189<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
scheibea2f9d512016-09-30 21:01:26190<td>Do not bind or store capturing lambdas outside the lifetime of the stack frame they are defined in. Captureless lambdas can be used with <code>base::Callback</code>, such as <code>base::Bind([](int j){}, i);</code>, because they offer protection against a large class of object lifetime mistakes. Don't use default captures (<code>[=]</code>, <code>[&amp;]</code> &ndash; <a href="https://google.github.io/styleguide/cppguide.html#Lambda_expressions">Google Style Guide</a>). Lambdas are typically useful as a parameter to methods or functions that will use them immediately, such as those in <code>&lt;algorithm&gt;</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnciQ">Discussion thread</a>, <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/QxjsPELDYdQ">uncapturing thread</a>.
191</td>
thakisa907c312014-11-04 23:38:06192</tr>
193
194<tr>
Nico Weber019d40f2014-09-23 20:21:59195<td>Local Types as Template Arguments</td>
pkasting0fcb7762016-04-29 00:44:37196<td><code>void func() {<br />
197&nbsp;&nbsp;class Pred {<br />
198&nbsp;&nbsp;&nbsp;public:<br />
199&nbsp;&nbsp;&nbsp;&nbsp;bool operator()(const T&) { ... }<br />
200&nbsp;&nbsp;};<br />
201&nbsp;&nbsp;std::remove_if(vec.begin(), vec.end(), Pred());</code></td>
Nico Weber019d40f2014-09-23 20:21:59202<td>Allows local and unnamed types as template arguments</td>
pkasting07c0959a2016-04-14 22:16:43203<td><a href="http://stackoverflow.com/questions/742607/using-local-classes-with-stl-algorithms">Local types, types without linkage and unnamed types as template arguments</a></td>
Nico Weber019d40f2014-09-23 20:21:59204<td>Usage should be rare. Approved without discussion.</td>
205</tr>
206
207<tr>
pkastingc6a6ebf12016-10-31 20:38:40208<td>Noexcept Specifier</td>
209<td><code>void f() noexcept</code></td>
210<td>Specifies that a function will not throw exceptions</td>
211<td><a href="http://en.cppreference.com/w/cpp/language/noexcept_spec">noexcept specifier</a></td>
212<td>Chromium compiles without exception support, but there are still cases where explicitly marking a function as <code>noexcept</code> may be necessary to compile, or for performance reasons. Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
213</tr>
214
215<tr>
hashimoto42a14e862015-01-22 15:21:41216<td>Non-Static Class Member Initializers</td>
pkasting07c0959a2016-04-14 22:16:43217<td><code>class C {<br />
218&nbsp;&nbsp;<i>type</i> <i>var</i> = <i>value</i>;<br />
219&nbsp;&nbsp;C()&nbsp;&nbsp;// copy-initializes <i>var</i></code>
hashimoto42a14e862015-01-22 15:21:41220<td>Allows non-static class members to be initialized at their definitions (outside constructors)</td>
pkasting07c0959a2016-04-14 22:16:43221<td><a href="http://en.cppreference.com/w/cpp/language/data_members">Non-static data members</a></td>
222<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zqB-DySA4V0">Discussion thread</a></td>
hashimoto42a14e862015-01-22 15:21:41223</tr>
224
225<tr>
danakj8bc9fc12014-09-24 20:45:29226<td>Null Pointer Constant</td>
227<td><code>nullptr</code></td>
228<td>Declares a type-safe null pointer</td>
pkasting7f0693b32016-10-31 20:27:50229<td><a href="http://en.cppreference.com/w/cpp/language/nullptr">nullptr, the pointer literal</a></td>
pkasting07c0959a2016-04-14 22:16:43230<td>Prefer over <code>NULL</code> or <code>0</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/4mijeJHzxLg">Discussion thread</a>. <a href="https://google.github.io/styleguide/cppguide.html#0_and_nullptr/NULL">Google Style Guide</a>. <code>std::nullptr_t</code> can be used too.</td>
danakj8bc9fc12014-09-24 20:45:29231</tr>
232
dcheng5f98d332014-09-24 22:12:10233<tr>
234<td>Override Specifier</td>
235<td><code>override</code></td>
236<td>Indicates that a class or function overrides a base implementation</td>
pkasting7f0693b32016-10-31 20:27:50237<td><a href="http://en.cppreference.com/w/cpp/language/override">override specifier</a></td>
pkasting07c0959a2016-04-14 22:16:43238<td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
dcheng5f98d332014-09-24 22:12:10239</tr>
240
241<tr>
Nico Weber3537d872014-09-25 19:10:04242<td>Range-Based For Loops</td>
243<td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td>
pkasting07c0959a2016-04-14 22:16:43244<td>Facilitates a more concise syntax for iterating over the elements of a container (or a range of iterators) in a <code>for</code> loop</td>
245<td><a href="http://en.cppreference.com/w/cpp/language/range-for">Range-based for loop</a></td>
Nico Weber3537d872014-09-25 19:10:04246<td>As a rule of thumb, use <code>for (const auto& ...)</code>, <code>for (auto& ...)</code>, or <code>for (<i>concrete type</i> ...)</code>. For pointers, use <code>for (auto* ...)</code> to make clear that the copy of the loop variable is intended, and only a pointer is copied. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc">Discussion thread</a></td>
247</tr>
248
249<tr>
danakj2c5aee92015-12-07 20:40:27250<td>Rvalue References</td>
pkasting07c0959a2016-04-14 22:16:43251<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)<br/><br/>
252template &lt;typename T&gt;<br/>void Function(T&& t) { ... }</code></td>
danakj2c5aee92015-12-07 20:40:27253<td>Reference that only binds to a temporary object</td>
pkasting7f0693b32016-10-31 20:27:50254<td><a href="http://en.cppreference.com/w/cpp/language/reference#Rvalue_references">Rvalue references</a></td>
dcheng1a2fd6cd2016-06-07 21:39:12255<td>As per the <a href="https://google.github.io/styleguide/cppguide.html#Rvalue_references">Google Style Guide</a>: Only use these to define move constructors and move assignment operators, and for perfect forwarding. Most classes should not be copyable, even if movable. Continue to use DISALLOW_COPY_AND_ASSIGN in most cases. <a href="https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/Q526tkruXpM">Another discussion thread</a>.</td>
danakj2c5aee92015-12-07 20:40:27256</tr>
257
258<tr>
dcheng5f98d332014-09-24 22:12:10259<td>Standard Integers</td>
pkasting07c0959a2016-04-14 22:16:43260<td>Typedefs within <code>&lt;stdint.h&gt;</code> and <code>&lt;inttypes&gt;</code></td>
dcheng5f98d332014-09-24 22:12:10261<td>Provides fixed-size integers independent of platforms</td>
pkasting7f0693b32016-10-31 20:27:50262<td><a href="http://en.cppreference.com/w/cpp/header/cstdint">Standard library header &lt;cstdint&gt;</a></td>
dcheng5f98d332014-09-24 22:12:10263<td>Already in common use in the codebase. Approved without discussion.</td>
264</tr>
265
Nico Weber3537d872014-09-25 19:10:04266<tr>
267<td>Static Assertions</td>
268<td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td>
269<td>Tests compile-time conditions</td>
270<td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Assertion</a></td>
271<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/POISBQEhGzU">Discussion thread</a></td>
272</tr>
273
274<tr>
mikhail.pozdnyakovbac797052016-05-16 15:48:10275<td>Trailing Return Types</td>
276<td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td>
277<td>Allows trailing function return value syntax</td>
278<td><a href="http://en.cppreference.com/w/cpp/language/function">Declaring functions</a></td>
279<td>Use only where it considerably improves readability. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Lkp0nubVd0Q">Another discussion thread.</a></td>
280</tr>
281
282<tr>
pkasting7f0693b32016-10-31 20:27:50283<td>Type Aliases ("using" instead of "typedef")</td>
284<td><code>using <i>new_alias</i> = <i>typename</i></code></td>
285<td>Allows parameterized typedefs</td>
286<td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias, alias template</a></td>
287<td>Use instead of typedef, unless the header needs to be compatible with C. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8dOAMzgR4ao">Discussion thread</a></td>
288</tr>
289
290<tr>
pkasting0fcb7762016-04-29 00:44:37291<td>Uniform Initialization Syntax</td>
292<td><code><i>type</i> <i>name</i> {[<i>value</i> ..., <i>value</i>]};</code></td>
293<td>Allows any object of primitive, aggregate or class type to be initialized using brace syntax</td>
294<td><a href="http://www.stroustrup.com/C++11FAQ.html#uniform-init">Uniform initialization syntax and semantics</a></td>
295<td>See the <a href="https://www.chromium.org/developers/coding-style/cpp-dos-and-donts?pli=1#TOC-Variable-initialization">Chromium C++ Dos And Don'ts guidance</a> on when to use this. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GF96FshwHLw">Discussion thread</a></td>
296</tr>
297
298<tr>
kwiberg882859a2016-08-16 09:42:21299<td>Union Class Members</td>
300<td><code>union <i>name</i> {<i>class</i> <i>var</i>}</code></td>
301<td>Allows class type members</td>
pkasting7f0693b32016-10-31 20:27:50302<td><a href="http://en.cppreference.com/w/cpp/language/union">Union declaration</a></td>
kwiberg882859a2016-08-16 09:42:21303<td>Usage should be rare.</td>
304</tr>
305
306<tr>
Nico Weber3537d872014-09-25 19:10:04307<td>Variadic Macros</td>
308<td><code>#define <i>MACRO</i>(...) <i>Impl</i>(<i>args</i>, __VA_ARGS__)</code></td>
309<td>Allows macros that accept a variable number of arguments</td>
pkasting07c0959a2016-04-14 22:16:43310<td><a href="http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard">Are Variadic macros nonstandard?</a></td>
Nico Weber3537d872014-09-25 19:10:04311<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/sRx9j3CQqyA">Discussion thread</a></td>
312</tr>
313
314<tr>
315<td>Variadic Templates</td>
316<td><code>template &lt;<i>typename</i> ... <i>arg</i>&gt;</code></td>
317<td>Allows templates that accept a variable number of arguments</td>
pkasting07c0959a2016-04-14 22:16:43318<td><a href="http://en.cppreference.com/w/cpp/language/parameter_pack">Parameter pack</a></td>
avi906dbd5c2014-09-26 22:11:42319<td>Usage should be rare. Use instead of .pump files. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/6ItymeMXpMc">Discussion thread</a></td>
Nico Weber3537d872014-09-25 19:10:04320</tr>
321
Nico Weber019d40f2014-09-23 20:21:59322</tbody>
323</table>
324
danakj4fd49fe42015-11-18 20:54:16325<h2 id="whitelist"><a name="library-whitelist"></a>C++11 Allowed Library Features</h2>
Nico Weberc8eb8ca2015-11-11 00:23:34326
327<p>The following library features are currently allowed.</p>
328
329<table id="whitelist_lib_list" class="unlined striped">
330<tbody>
331
332<tr>
333<th style='width:240px;'>Feature or Library</th>
334<th style='width:240px;'>Snippet</th>
335<th style='width:240px;'>Description</th>
336<th style='width:240px;'>Documentation Link</th>
337<th style='width:240px;'>Notes</th>
338</tr>
339
340<tr>
davidben4507eaa2015-11-19 19:07:06341<td>Access to underlying <code>std::vector</code> data</td>
342<td><code>v.data()</code></td>
343<td>Returns a pointer to a <code>std::vector</code>'s underlying data, accounting for empty vectors.</td>
344<td><a href="http://en.cppreference.com/w/cpp/container/vector/data">std::vector::data</a></td>
pkasting2f966af2015-12-06 01:52:18345<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16V7fmtbzok">Discussion thread</a></td>
davidben4507eaa2015-11-19 19:07:06346</tr>
347
348<tr>
pkasting3adbbcc2016-02-04 01:52:38349<td>Algorithms</td>
350<td>All C++11 features in <code>&lt;algorithm&gt;</code>:<br/>
351<code>all_of</code>, <code>any_of</code>, <code>none_of</code><br/>
352<code>find_if_not</code><br/>
353<code>copy_if</code>, <code>copy_n</code><br/>
354<code>move</code>, <code>move_backward</code> (see note)<br/>
355<code>shuffle</code><br/>
356<code>is_partitioned</code>, <code>partition_copy</code>, <code>partition_point</code><br/>
357<code>is_sorted</code>, <code>is_sorted_until</code><br/>
358<code>is_heap</code>, <code>is_heap_until</code><br/>
359<code>minmax</code>, <code>minmax_element</code><br/>
pkasting07c0959a2016-04-14 22:16:43360<code>is_permutation<br/></td>
pkasting3adbbcc2016-02-04 01:52:38361<td>Safe and performant implementations of common algorithms</td>
pkasting7f0693b32016-10-31 20:27:50362<td><a href="http://en.cppreference.com/w/cpp/header/algorithm">Standard library header &lt;algorithm&gt;</a></td>
pkasting07c0959a2016-04-14 22:16:43363<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/UJQk8S1IuHk">Discussion thread</a><br/> Note that &lt;algorithm&gt; contains a range-based <code>move</code> method. This is allowed, but because people may confuse it with the single-arg <code>std::move</code>, there is often a way to write code without it that is more readable. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/8WzmtYrZvQ8'>Discussion thread</a></td>
pkasting3adbbcc2016-02-04 01:52:38364</tr>
365
366<tr>
ruudab425288a2015-11-23 21:46:57367<td>Begin and End Non-Member Functions</td>
pkasting07c0959a2016-04-14 22:16:43368<td><code>std::begin()</code>, <code>std::end()</code></td>
pkastinga234a072016-02-11 01:35:53369<td>Allows use of free functions on any container, including fixed-size arrays</td>
pkasting07c0959a2016-04-14 22:16:43370<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">std::begin</a>, <a href="http://en.cppreference.com/w/cpp/iterator/end">std::end</a></td>
371<td>Useful for fixed-size arrays. Note that non-member <code>cbegin()</code> and <code>cend()</code> are not available until C++14. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/5iFNE8P5qT4/discussion">Discussion thread</a></td>
ruudab425288a2015-11-23 21:46:57372</tr>
373
374<tr>
pkasting2f966af2015-12-06 01:52:18375<td>Conditional Type Selection</td>
pkasting07c0959a2016-04-14 22:16:43376<td><code>std::enable_if</code>, <code>std::conditional</code></td>
pkasting2f966af2015-12-06 01:52:18377<td>Enables compile-time conditional type selection</td>
pkasting07c0959a2016-04-14 22:16:43378<td><a href="http://en.cppreference.com/w/cpp/types/enable_if">std::enable_if</a>, <a href="http://en.cppreference.com/w/cpp/types/conditional">conditional</a></td>
pkasting2f966af2015-12-06 01:52:18379<td>Usage should be rare. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
380</tr>
381
382<tr>
pkastinga234a072016-02-11 01:35:53383<td>Constant Iterator Methods on Containers</td>
pkasting07c0959a2016-04-14 22:16:43384<td>E.g. <code>std::vector::cbegin()</code>, <code>std::vector::cend()</code></td>
pkastinga234a072016-02-11 01:35:53385<td>Allows more widespread use of <code>const_iterator</code></td>
pkasting07c0959a2016-04-14 22:16:43386<td><a href="http://en.cppreference.com/w/cpp/container/vector/begin">std::vector::cbegin</a>, <a href="http://en.cppreference.com/w/cpp/container/vector/end">std::vector::cend<a></td>
387<td>Applies to all containers, not just <code>vector</code>. Consider using <code>const_iterator</code> over <code>iterator</code> where possible for the same reason as using <code>const</code> variables and functions where possible; see Effective Modern C++ item 13 for motivation. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/cS83F_buqLM/discussion">Discussion thread</a></td>
pkastinga234a072016-02-11 01:35:53388</tr>
389
390<tr>
pkasting7f0693b32016-10-31 20:27:50391<td>Containers containing move-only types</td>
Nico Weberc8eb8ca2015-11-11 00:23:34392<td><code>vector&lt;scoped_ptr&gt;</code></td>
393<td>Enables containers that contain move-only types like <code>scoped_ptr</code></td>
394<td>TODO</td>
pkasting07c0959a2016-04-14 22:16:43395<td>Prefer over <a href="http://crbug.com/554289">ScopedVector</a>.</td>
396</tr>
397
398<tr>
399<td>Declared Type As Value</td>
400<td><code>std::declval&lt;<i>class</i>&gt;()</code></td>
401<td>Converts a type to a reference of the type to allow use of members of the type without constructing it in templates.</td>
402<td><a href="http://en.cppreference.com/w/cpp/utility/declval">std::declval</a></td>
403<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/ku6lYjk0-OU/discussion">Discussion thread</a></td>
Nico Weberc8eb8ca2015-11-11 00:23:34404</tr>
jsbella882f622015-11-13 02:02:14405
406<tr>
pkasting53121c42016-02-04 22:14:36407<td>Emplacement methods for containers</td>
408<td><code>emplace()</code>, <code>emplace_back()</code>, <code>emplace_front()</code>, <code>emplace_hint()</code></td>
pkasting07c0959a2016-04-14 22:16:43409<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>
pkasting53121c42016-02-04 22:14:36410<td>E.g. <a href="http://en.cppreference.com/w/cpp/container/vector/emplace_back">std::vector::emplace_back</a></td>
pkasting07c0959a2016-04-14 22:16:43411<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>
pkasting53121c42016-02-04 22:14:36412</tr>
413
414<tr>
davidben411d3f72016-01-22 01:41:41415<td>Forwarding references</td>
416<td><code>std::forward()</code></td>
417<td>Perfectly forwards arguments (including rvalues)</td>
pkasting0fcb7762016-04-29 00:44:37418<td><a href="http://en.cppreference.com/w/cpp/utility/forward">std::forward</a></td>
pkasting07c0959a2016-04-14 22:16:43419<td>Allowed, though usage should be rare (primarily for forwarding constructor arguments, or in carefully reviewed library code). <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/-O7euklhSxs/discussion">Discussion thread</a>
davidben411d3f72016-01-22 01:41:41420</td>
421</tr>
422
423<tr>
pkasting0fcb7762016-04-29 00:44:37424<td>Initializer Lists</td>
425<td><code>std::initializer_list&lt;T&gt;</code></td>
426<td>Allows containers to be initialized with aggregate elements</td>
427<td><a href="http://en.cppreference.com/w/cpp/utility/initializer_list">std::initializer_list</a></td>
428<td>Be cautious adding new constructors which take these, as they can hide non-initializer_list constructors in undesirable ways; see Effective Modern C++ Item 7 for more.</td>
429</tr>
430
431<tr>
pkasting3adbbcc2016-02-04 01:52:38432<td>Math functions</td>
433<td>All C++11 features in <code>&lt;cmath&gt;</code>, e.g.:<br/>
434<code>INFINITY</code>, <code>NAN</code>, <code>FP_NAN</code><br/>
435<code>float_t</code>, <code>double_t</code><br/>
436<code>fmax</code>, <code>fmin</code>, <code>trunc</code>, <code>round</code><br/>
437<code>isinf</code>, <code>isnan</code><br/></td>
438<td>Useful for math-related code</td>
pkasting7f0693b32016-10-31 20:27:50439<td><a href="http://en.cppreference.com/w/cpp/header/cmath">Standard library header &lt;cmath&gt;</a></td>
pkasting3adbbcc2016-02-04 01:52:38440<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/P-1bFBXMeUk">Discussion thread</a></td>
441</tr>
442
443<tr>
pkasting2f966af2015-12-06 01:52:18444<td>Move Iterator Adaptor</td>
445<td><code>std::make_move_iterator()</code></td>
446<td>Wraps an iterator so that it moves objects instead of copying them.</td>
447<td><a href="http://en.cppreference.com/w/cpp/iterator/make_move_iterator">std::make_move_iterator</a></td>
448<td>Useful to move objects between containers that contain move-only types like <code>scoped_ptr</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/lccnUljOHQU">Discussion thread</a></td>
vmpstrf484f722015-11-16 23:10:31449</tr>
450
vmpstrc52317f2015-11-18 08:43:26451<tr>
pkasting2f966af2015-12-06 01:52:18452<td>Move Semantics</td>
453<td><code>std::move()</code></td>
454<td>Facilitates efficient move operations</td>
pkasting0fcb7762016-04-29 00:44:37455<td><a href="http://en.cppreference.com/w/cpp/utility/move">std::move</a></td>
danakj2c5aee92015-12-07 20:40:27456<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
vmpstrc52317f2015-11-18 08:43:26457</tr>
458
459<tr>
pkasting9022cb42016-02-05 00:08:56460<td>String Direct Reference Functions</td>
pkasting07c0959a2016-04-14 22:16:43461<td><code>std::string::front()</code>, <code>std::string::back()</code></td>
pkasting9022cb42016-02-05 00:08:56462<td>Returns a reference to the front or back of a string</td>
pkasting07c0959a2016-04-14 22:16:43463<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/front">std::basic_string::front</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/back">std::basic_string::back</a></td>
pkasting9022cb42016-02-05 00:08:56464<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/DRJuROAYCV4">Discussion thread</a></td>
465</tr>
466
467<tr>
vmpstrc52317f2015-11-18 08:43:26468<td>Type Traits</td>
pkasting3adbbcc2016-02-04 01:52:38469<td>All C++11 features in <code>&lt;type_traits&gt;</code> except for aligned storage (see separate item), e.g.:<br/>
470<code>integral_constant</code><br/>
471<code>is_floating_point</code>, <code>is_rvalue_reference</code>, <code>is_scalar</code><br/>
472<code>is_const</code>, <code>is_pod</code>, <code>is_unsigned</code><br/>
473<code>is_default_constructible</code>, <code>is_move_constructible</code>, <code>is_copy_assignable</code><br/>
pkasting07c0959a2016-04-14 22:16:43474<code>enable_if</code>, <code>conditional</code>, <code>result_of</code><br/></td>
vmpstrc52317f2015-11-18 08:43:26475<td>Allows compile-time inspection of the properties of types</td>
pkasting7f0693b32016-10-31 20:27:50476<td><a href="http://en.cppreference.com/w/cpp/header/type_traits">Standard library header &lt;type_traits&gt;</a></td>
pkasting07c0959a2016-04-14 22:16:43477<td>Note that not all type traits are available on all platforms (e.g. <code>std::underlying_type</code> doesn't work in libstdc++4.6). Use judiciously. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
vmpstrc52317f2015-11-18 08:43:26478</tr>
479
ricea5db2dfe2015-12-04 14:26:46480<tr>
dcheng7bebfa462016-04-03 23:15:25481<td>Tuples</td>
pkasting00ebe862016-05-11 01:48:50482<td>All C++11 features in <code>&lt;tuple&gt;</code>, e.g. <code>std::tie</code> and <code>std::tuple</code>.</td>
dcheng7bebfa462016-04-03 23:15:25483<td>A fixed-size ordered collection of values of mixed types</td>
pkasting7f0693b32016-10-31 20:27:50484<td><a href="http://en.cppreference.com/w/cpp/header/tuple">Standard library header &lt;tuple&gt;</a></td>
tzikec749b12016-06-24 00:33:47485<td>Use <code>base::get</code> instead of <code>std::get</code> in case the <code>std::tuple</code> may be a rvalue-reference.
486<code>std::get</code> in &lt;=libstdc++-4.6 misses an overload for rvalue-reference of a tuple, and <code>base::get</code> complements it. </td>
dcheng7bebfa462016-04-03 23:15:25487</tr>
488
489<tr>
davidben411d3f72016-01-22 01:41:41490<td>Unordered Associative Containers</td>
pkasting07c0959a2016-04-14 22:16:43491<td><code>std::unordered_set</code>, <code>std::unordered_map</code>, <code>std::unordered_multiset</code>, <code>std::unordered_multimap</code></td>
davidben411d3f72016-01-22 01:41:41492<td>Allows efficient containers of key/value pairs</td>
pkasting07c0959a2016-04-14 22:16:43493<td><a href="http://en.cppreference.com/w/cpp/container/unordered_map">std::unordered_map</a>, <a href="http://en.cppreference.com/w/cpp/container/unordered_set">std::unordered_set</a></td>
494<td>Per the <a href="https://google.github.io/styleguide/cppguide.html#std_hash">Google Style Guide</a>, specify custom hashers instead of specializing <code>std::hash</code> for custom types. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/nCdjQqnouO4">Discussion thread</a>.</td>
davidben411d3f72016-01-22 01:41:41495</tr>
496
tzik9ca302192016-02-11 10:24:45497<tr>
dcheng7bebfa462016-04-03 23:15:25498<td>Unique Pointers</td>
499<td><code>std::unique_ptr&lt;<i>type</i>&gt;</code></td>
500<td>A smart pointer with sole ownership of the owned object.</td>
501<td><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr">std::unique_ptr</a></td>
pkasting07c0959a2016-04-14 22:16:43502<td>Use in all newly written code. <a href="https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/aT2wsBLKvzI/oZuZ718oAwAJ">Discussion thread</a>. <code>scoped_ptr</code> is a <a href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/roY78iTblYc/bb8nYsxfCgAJ">typedef for <code>std::unique_ptr</code></a> and is going away shortly.</td>
tzik9ca302192016-02-11 10:24:45503</tr>
504
Nico Weberc8eb8ca2015-11-11 00:23:34505</tbody>
506</table>
507
Nico Weber019d40f2014-09-23 20:21:59508<h2 id="blacklist">C++11 Blacklist (Disallowed and Banned Features)</h2>
509
510<p>This section lists features that are not allowed to be used yet.
511
danakj4fd49fe42015-11-18 20:54:16512<h3 id="blacklist_banned"><a name="core-blacklist"></a>C++11 Banned Features</h3>
Nico Weber019d40f2014-09-23 20:21:59513
mdempsky33bafda2014-10-30 23:14:52514<p>This section lists C++11 features that are not allowed in the Chromium
Nico Webercea20a82014-09-25 17:46:51515codebase.
Nico Weber019d40f2014-09-23 20:21:59516</p>
517
Nico Weber019d40f2014-09-23 20:21:59518<table id="banned_list" class="unlined striped">
519<tbody>
520
521<tr>
522<th style='width:240px;'>Feature or Library</th>
523<th style='width:240px;'>Snippet</th>
524<th style='width:240px;'>Description</th>
525<th style='width:240px;'>Documentation Link</th>
Nico Webercea20a82014-09-25 17:46:51526<th style='width:240px;'>Notes</th>
527</tr>
528
529<tr>
yutak175dd5b2015-12-08 21:51:24530<td>Alignment Features</td>
pkasting07c0959a2016-04-14 22:16:43531<td><code>alignas</code> specifier, <code>alignof</code> operator</td>
yutak175dd5b2015-12-08 21:51:24532<td>Object alignment</td>
pkasting7f0693b32016-10-31 20:27:50533<td><a href="http://en.cppreference.com/w/cpp/language/alignas">alignas specifier</a>, <a href="http://en.cppreference.com/w/cpp/language/alignof">alignof operator</a></td>
pkasting07c0959a2016-04-14 22:16:43534<td>Reevaluate now that MSVS2015 is available. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/rwXN02jzzq0/CpUc1ZzMBQAJ">Discussion thread</a></td>
yutak175dd5b2015-12-08 21:51:24535</tr>
536
537<tr>
mdempsky33bafda2014-10-30 23:14:52538<td>Inherited Constructors</td>
pkasting07c0959a2016-04-14 22:16:43539<td><code>class Derived : Base {<br />
540&nbsp;&nbsp;using Base::Base;<br />
541};</code></td>
mdempsky33bafda2014-10-30 23:14:52542<td>Allow derived classes to inherit constructors from base classes</td>
543<td><a href="http://en.cppreference.com/w/cpp/language/using_declaration">Using-declaration</a></td>
pkasting07c0959a2016-04-14 22:16:43544<td>Reevaluate now that MSVS2015 is available. <a href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/BULzgIKZ-Ao/PLO7_GoVNvYJ">Discussion thread</a></td>
mdempsky33bafda2014-10-30 23:14:52545</tr>
546
547<tr>
thakis12bfc742014-10-28 04:37:49548<td><code>long long</code> Type</td>
pkasting7f0693b32016-10-31 20:27:50549<td><code>long long <i>var</i> = <i>value</i>;</code></td>
thakis12bfc742014-10-28 04:37:49550<td>An integer of at least 64 bits</td>
pkasting07c0959a2016-04-14 22:16:43551<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
552<td>Use a stdint.h type if you need a 64bit number. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk">Discussion thread</a></td>
thakis12bfc742014-10-28 04:37:49553</tr>
554
555<tr>
556<td>Raw String Literals</td>
557<td><code>string <i>var</i>=R&quot;(<i>raw_string</i>)&quot;;</code></td>
pkasting07c0959a2016-04-14 22:16:43558<td>Allows a string to be encoded without any escape sequences, easing parsing in regex expressions, for example</td>
559<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
brucedawsond174d802015-11-06 18:37:54560<td>Causes incorrect line numbers in MSVS2013 and gcc. Reevaluate once that works. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
thakis12bfc742014-10-28 04:37:49561</tr>
562
563<tr>
Nico Webercea20a82014-09-25 17:46:51564<td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td>
565<td><code>char16_t</code> and <code>char32_t</code></td>
pkasting07c0959a2016-04-14 22:16:43566<td>Provides character types for handling 16-bit and 32-bit code units (useful for encoding UTF-16 and UTF-32 string data)</td>
567<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
568<td>Reevaluate now that MSVS2015 is available. Non-UTF-8 text is banned by the <a href="https://google.github.io/styleguide/cppguide.html#Non-ASCII_Characters">Google Style Guide</a>. However, may be useful for consuming non-ASCII data. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ME2kL7_Kvyk">Discussion thread</a></td>
Nico Webercea20a82014-09-25 17:46:51569</tr>
570
571<tr>
572<td>UTF-8, UTF-16, UTF-32 String Literals</td>
573<td><code>u8&quot;<i>string</i>&quot;, u&quot;<i>string</i>&quot;, U&quot;<i>string</i>&quot;</code></td>
574<td>Enforces UTF-8, UTF-16, UTF-32 encoding on all string literals</td>
pkasting07c0959a2016-04-14 22:16:43575<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
576<td>Reevaluate now that MSVS2015 is available. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/gcoUbcjfsII">Discussion thread</a></td>
Nico Weber019d40f2014-09-23 20:21:59577</tr>
578
jbromand21995c52016-01-07 23:43:54579<tr>
580<td>Ref-qualified Member Functions</td>
pkasting07c0959a2016-04-14 22:16:43581<td><code>class T {<br />
582&nbsp;&nbsp;void f() & {}<br />
583&nbsp;&nbsp;void f() && {}<br />
584};<br />
585t.f();&nbsp;&nbsp;// first<br />
586T().f();&nbsp;&nbsp;// second<br />
587std::move(t).f();&nbsp;&nbsp;// second</code></td>
jbromand21995c52016-01-07 23:43:54588<td>Allows class member functions to only bind to |this| as an rvalue or lvalue.</td>
pkasting7f0693b32016-10-31 20:27:50589<td><a href="http://en.cppreference.com/w/cpp/language/member_functions#const-.2C_volatile-.2C_and_ref-qualified_member_functions">const-, volatile-, and ref-qualified member functions</a></td>
590<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a>. May only be used in Chromium with explicit approval from <code>styleguide/c++/OWNERS</code>. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/gowclr2LPQA/discussion">Discussion Thread</a></td>
jbromand21995c52016-01-07 23:43:54591</tr>
592
Nico Weber019d40f2014-09-23 20:21:59593</tbody>
594</table>
Nico Weber019d40f2014-09-23 20:21:59595
danakj4fd49fe42015-11-18 20:54:16596<h3 id="blacklist_stdlib"><a name="library-blacklist"></a>C++11 Banned Library Features</h3>
Nico Weberc8eb8ca2015-11-11 00:23:34597
598<p>This section lists C++11 library features that are not allowed in the Chromium codebase.</p>
599
600<table id="blacklist_lib_list" class="unlined striped">
601<tbody>
602
603<tr>
604<th style='width:240px;'>Feature</th>
605<th style='width:240px;'>Snippet</th>
606<th style='width:240px;'>Description</th>
607<th style='width:240px;'>Documentation Link</th>
608<th style='width:240px;'>Notes</th>
609</tr>
610
611<tr>
pkasting7f0693b32016-10-31 20:27:50612<td>Date and time utilities</td>
Nico Weberc8eb8ca2015-11-11 00:23:34613<td><code>&lt;chrono&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50614<td>A standard date and time library</td>
Nico Weberc8eb8ca2015-11-11 00:23:34615<td><a href="http://en.cppreference.com/w/cpp/chrono">Date and time utilities</a></td>
pkasting7f0693b32016-10-31 20:27:50616<td>Overlaps with <code>Time</code> APIs in <code>base/</code>. Keep using the <code>base/</code> classes.</td>
Nico Weberc8eb8ca2015-11-11 00:23:34617</tr>
618
619<tr>
pkastingc6a6ebf12016-10-31 20:38:40620<td>Exceptions</td>
621<td><code>&lt;exception&gt;</code></td>
622<td>Enhancements to exception throwing and handling</td>
623<td><a href="http://en.cppreference.com/w/cpp/header/exception">Standard library header &lt;exception&gt;</a></td>
624<td>Exceptions are banned by the <a href="https://google.github.io/styleguide/cppguide.html#Exceptions">Google Style Guide</a> and disabled in Chromium compiles. Note that the <code>noexcept</code> specifier is explicitly allowed above. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
625</tr>
626
627<tr>
pkasting7f0693b32016-10-31 20:27:50628<td>Regular Expressions</td>
Nico Weberc8eb8ca2015-11-11 00:23:34629<td><code>&lt;regex&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50630<td>A standard regular expressions library</td>
Nico Weberc8eb8ca2015-11-11 00:23:34631<td><a href="http://en.cppreference.com/w/cpp/regex">Regular expressions library</a></td>
pkasting7f0693b32016-10-31 20:27:50632<td>Overlaps with many regular expression libraries in Chromium. When in doubt, use re2.</td>
Nico Weberc8eb8ca2015-11-11 00:23:34633</tr>
634
635<tr>
636<td>Thread Library</td>
pkasting7f0693b32016-10-31 20:27:50637<td><code>&lt;thread&gt;</code> and related headers, including<br />
pkasting07c0959a2016-04-14 22:16:43638<code>&lt;future&gt;</code>, <code>&lt;mutex&gt;</code>, <code>&lt;condition_variable&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50639<td>Provides a standard multithreading library using <code>std::thread</code> and associates</td>
Nico Weberc8eb8ca2015-11-11 00:23:34640<td><a href="http://en.cppreference.com/w/cpp/thread">Thread support library</a></td>
pkasting7f0693b32016-10-31 20:27:50641<td>Overlaps with many classes in <code>base/</code>. Keep using the <code>base/</code> classes for now. <code>base::Thread</code> is tightly coupled to <code>MessageLoop</code> which would make it hard to replace. We should investigate using standard mutexes, or unique_lock, etc. to replace our locking/synchronization classes.</td>
Nico Weberc8eb8ca2015-11-11 00:23:34642</tr>
643
jbromand21995c52016-01-07 23:43:54644<tr>
645<td>Atomics</td>
pkasting7f0693b32016-10-31 20:27:50646<td><code>&lt;atomic&gt;</code></td>
jbromand21995c52016-01-07 23:43:54647<td>Fine-grained atomic types and operations</td>
pkasting7f0693b32016-10-31 20:27:50648<td><a href="http://en.cppreference.com/w/cpp/atomic">Atomic operations library</a></td>
jbromand21995c52016-01-07 23:43:54649<td>Use in tcmalloc has caused <a href="http://crbug.com/572525">performance regressions</a>. Banned until we understand this better. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/Ej3RAiaI44s/discussion">Discussion Thread</a></td>
650</tr>
651
652<tr>
653<td>Shared Pointers</td>
654<td><code>std::shared_ptr</code></td>
655<td>Allows shared ownership of a pointer through reference counts</td>
656<td><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr">std::shared_ptr</a></td>
pkasting07c0959a2016-04-14 22:16:43657<td>Needs a lot more evaluation for Chromium, and there isn't enough of a push for this feature. <a href="https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/aT2wsBLKvzI/discussion">Discussion Thread</a>.</td>
jbromand21995c52016-01-07 23:43:54658</tr>
659
Nico Weberc8eb8ca2015-11-11 00:23:34660</tbody>
661</table>
662
663
danakj4fd49fe42015-11-18 20:54:16664<h3 id="blacklist_review"><a name="core-review"></a>C++11 Features To Be Discussed</h3>
Nico Weber019d40f2014-09-23 20:21:59665
666<p>The following C++ language features are currently disallowed.
667See the top of this page on how to propose moving a feature from this list
668into the allowed or banned sections. Note that not all of these features
669work in all our compilers yet.</p>
670
671<table id="blacklist_review_list" class="unlined striped">
672<tbody>
673
674<tr>
675<th style='width:240px;'>Feature</th>
676<th style='width:240px;'>Snippet</th>
677<th style='width:240px;'>Description</th>
678<th style='width:240px;'>Documentation Link</th>
679<th style='width:240px;'>Notes</th>
680</tr>
681
682<tr>
Nico Weber019d40f2014-09-23 20:21:59683<td>Attributes</td>
684<td><code>[[<i>attribute_name</i>]]</code></td>
pkasting07c0959a2016-04-14 22:16:43685<td>Attaches properties to declarations that specific compiler implementations may use.</td>
686<td><a href="http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/">C++11 generalized attributes</a></td>
Nico Weber019d40f2014-09-23 20:21:59687<td></td>
688</tr>
689
690<tr>
Nico Weber019d40f2014-09-23 20:21:59691<td>Inline Namespaces</td>
pkasting7f0693b32016-10-31 20:27:50692<td><code>inline namespace foo { ... }</code></td>
Nico Weber019d40f2014-09-23 20:21:59693<td>Allows better versioning of namespaces</td>
pkasting7f0693b32016-10-31 20:27:50694<td><a href="http://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces">Inline namespaces</a></td>
695<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#Namespaces">Google Style Guide</a>. Unclear how it will work with components.</td>
Nico Weber019d40f2014-09-23 20:21:59696</tr>
697
698<tr>
Nico Weber019d40f2014-09-23 20:21:59699<td>User-Defined Literals</td>
700<td><code><i>type</i> <i>var</i> = <i>literal_value</i>_<i>type</i></code></td>
701<td>Allows user-defined literal expressions</td>
pkasting07c0959a2016-04-14 22:16:43702<td><a href="http://en.cppreference.com/w/cpp/language/user_literal">User-defined literals</a></td>
pkasting7f0693b32016-10-31 20:27:50703<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#Operator_Overloading">Google Style Guide</a>.</td>
Nico Weber019d40f2014-09-23 20:21:59704</tr>
705
Nico Weber019d40f2014-09-23 20:21:59706</tbody>
707</table>
708
danakj4fd49fe42015-11-18 20:54:16709<h3 id="blacklist_stdlib_review"><a name="library-review"></a>C++11 Standard Library Features To Be Discussed</h3>
Nico Weber019d40f2014-09-23 20:21:59710
Nico Weberc8eb8ca2015-11-11 00:23:34711<p>The following C++ library features are currently disallowed. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections. Note that not all of these features work in all our compilers yet.</p>
Nico Weber019d40f2014-09-23 20:21:59712
713<table id="banned_stdlib" class="unlined striped">
714
715<tbody>
716<tr>
717<th style='width:240px;'>Feature</th>
718<th style='width:240px;'>Snippet</th>
719<th style='width:240px;'>Description</th>
720<th style='width:240px;'>Documentation Link</th>
721<th style='width:240px;'>Style Guide Usage</th>
722</tr>
723
724<tr>
725<td>Address Retrieval</td>
726<td><code>std::addressof()</code></td>
727<td>Obtains the address of an object even with overloaded <code>operator&amp;</code></td>
728<td><a href="http://en.cppreference.com/w/cpp/memory/addressof">std::addressof</a></td>
pkasting07c0959a2016-04-14 22:16:43729<td>Usage should be rare as <a href="https://google.github.io/styleguide/cppguide.html#Operator_Overloading">operator overloading</a> is rare and <code>&amp;</code> should suffice in most cases. May be preferable over <code>&amp;</code> for performing object identity checks.</td>
Nico Weber019d40f2014-09-23 20:21:59730</tr>
731
732<tr>
733<td>Aligned Storage</td>
pkasting07c0959a2016-04-14 22:16:43734<td><code>std::aligned_storage&lt;Size, Align&gt;::type</code><br />
735<code>std::alignment_of&lt;T&gt;</code>, <code>std::aligned_union&lt;Size, ...Types&gt;</code> <code>std::max_align_t</code></td>
danakj715179fc2015-11-12 05:32:18736<td>Declare uninitialized storage having a specified alignment, or determine alignments.</td>
Nico Weber019d40f2014-09-23 20:21:59737<td><a href="http://en.cppreference.com/w/cpp/types/aligned_storage">std::aligned_storage</a></td>
pkasting07c0959a2016-04-14 22:16:43738<td><code>std::aligned_storage</code> and <code>std::aligned_union</code> are disallowed in google3 over concerns about compatibility with internal cross-compiling toolchains.</td>
Nico Weber019d40f2014-09-23 20:21:59739</tr>
740
741<tr>
742<td>Allocator Traits</td>
743<td><code>std::allocator_traits</code></td>
744<td>Provides an interface for accessing custom allocators</td>
pkasting07c0959a2016-04-14 22:16:43745<td><a href="http://en.cppreference.com/w/cpp/memory/allocator_traits">std::allocator_traits</a></td>
Nico Weber019d40f2014-09-23 20:21:59746<td>Usage should be rare.</td>
747</tr>
748
749<tr>
Nico Weber019d40f2014-09-23 20:21:59750<td>Bind Operations</td>
751<td><code>std::bind(<i>function</i>, <i>args</i>, ...)</code></td>
752<td>Declares a function object bound to certain arguments</td>
pkasting7f0693b32016-10-31 20:27:50753<td><a href="http://en.cppreference.com/w/cpp/utility/functional/bind">std::bind</a></td>
Nico Weber019d40f2014-09-23 20:21:59754<td></td>
755</tr>
756
757<tr>
758<td>C Floating-Point Environment</td>
danakj715179fc2015-11-12 05:32:18759<td><code>&lt;cfenv&gt;</code>, <code>&lt;fenv.h&gt;</code></td>
Nico Weber019d40f2014-09-23 20:21:59760<td>Provides floating point status flags and control modes for C-compatible code</td>
761<td><a href="http://en.cppreference.com/w/cpp/header/cfenv">Standard library header &lt;cfenv&gt;</a></td>
pkasting07c0959a2016-04-14 22:16:43762<td>Banned in <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns about compiler support.</td>
Nico Weber019d40f2014-09-23 20:21:59763</tr>
764
765<tr>
Nico Weber019d40f2014-09-23 20:21:59766<td>Complex Inverse Trigonometric and Hyperbolic Functions</td>
767<td>Functions within <code>&lt;complex&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:43768<td>Adds inverse trigonomentric and hyperbolic non-member functions to the <code>&lt;complex&gt;</code> library.</td>
Nico Weber019d40f2014-09-23 20:21:59769<td><a href="http://en.cppreference.com/w/cpp/numeric/complex">std::complex</a></td>
770<td></td>
771</tr>
772
773<tr>
Nico Weber019d40f2014-09-23 20:21:59774<td>Container Compaction Functions</td>
pkasting07c0959a2016-04-14 22:16:43775<td><code>std::vector::shrink_to_fit()</code>, <code>std::deque::shrink_to_fit()</code>, <code>std::string::shrink_to_fit()</code></td>
776<td>Requests the removal of unused space in the container</td>
777<td><a href="http://en.cppreference.com/w/cpp/container/vector/shrink_to_fit">std::vector::shrink_to_fit</a>, <a href="http://en.cppreference.com/w/cpp/container/deque/shrink_to_fit">std::deque::shrink_to_fit</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/shrink_to_fit">std::basic_string::shrink_to_fit</a></td>
Nico Weber019d40f2014-09-23 20:21:59778<td></td>
779</tr>
780
781<tr>
782<td>Date/Time String Formatting Specifiers</td>
783<td><code>std::strftime()</code></td>
pkasting07c0959a2016-04-14 22:16:43784<td>Converts date and time information into a formatted string using new specifiers</td>
785<td><a href="http://en.cppreference.com/w/cpp/chrono/c/strftime">std::strftime</a></td>
Nico Weber019d40f2014-09-23 20:21:59786<td></td>
787</tr>
788
789<tr>
790<td>Function Return Type Deduction</td>
791<td><code>std::result_of&lt;<i>Functor(ArgTypes...)</i>&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:43792<td>Extracts the return type from the type signature of a function call invocation at compile-time.</td>
793<td><a href="http://en.cppreference.com/w/cpp/types/result_of">std::result_of</a></td>
794<td><a href="http://stackoverflow.com/questions/15486951/why-does-stdresult-of-take-an-unrelated-function-type-as-a-type-argument">Why does std::result_of take an (unrelated) function type as a type argument?</a></td>
Nico Weber019d40f2014-09-23 20:21:59795</tr>
796
797<tr>
798<td>Function Objects</td>
799<td><code>std::function</code></td>
800<td>Wraps a standard polymorphic function</td>
pkasting7f0693b32016-10-31 20:27:50801<td><a href="http://en.cppreference.com/w/cpp/utility/functional/function">std::function</a></td>
Nico Weber019d40f2014-09-23 20:21:59802<td></td>
803</tr>
804
805<tr>
806<td>Forward Lists</td>
807<td><code>std::forward_list</code></td>
808<td>Provides an efficient singly linked list</td>
pkasting07c0959a2016-04-14 22:16:43809<td><a href="http://en.cppreference.com/w/cpp/container/forward_list">std::forward_list</a></td>
Nico Weber019d40f2014-09-23 20:21:59810<td></td>
811</tr>
812
813<tr>
814<td>Gamma Natural Log</td>
815<td><code>std::lgamma()</code></td>
pkasting07c0959a2016-04-14 22:16:43816<td>Computes the natural log of the gamma of a floating point value</td>
817<td><a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma">std::lgamma</a></td>
Nico Weber019d40f2014-09-23 20:21:59818<td></td>
819</tr>
820
821<tr>
822<td>Garbage Collection Features</td>
pkasting07c0959a2016-04-14 22:16:43823<td><code>std::{un}declare_reachable()</code>, <code>std::{un}declare_no_pointers()</code></td>
Nico Weber019d40f2014-09-23 20:21:59824<td>Enables garbage collection implementations</td>
pkasting07c0959a2016-04-14 22:16:43825<td><a href="http://en.cppreference.com/w/cpp/memory/gc/declare_reachable">std::declare_reachable</a>, <a href="http://en.cppreference.com/w/cpp/memory/gc/declare_no_pointers">std::declare_no_pointers</a></td>
Nico Weber019d40f2014-09-23 20:21:59826<td></td>
827</tr>
828
829<tr>
Nico Weber019d40f2014-09-23 20:21:59830<td>Iterator Operators</td>
pkasting07c0959a2016-04-14 22:16:43831<td><code>std::next()</code>, <code>std::prev()</code></td>
832<td>Copies an iterator and increments or decrements the copy by some value</td>
833<td><a href="http://en.cppreference.com/w/cpp/iterator/next">std::next</a>, <a href="http://en.cppreference.com/w/cpp/iterator/prev">std::prev</a></td>
Nico Weber019d40f2014-09-23 20:21:59834<td></td>
835</tr>
836
837<tr>
Nico Weber019d40f2014-09-23 20:21:59838<td>Pointer Traits Class Template</td>
839<td><code>std::pointer_traits</code></td>
pkasting07c0959a2016-04-14 22:16:43840<td>Provides a standard way to access properties of pointers and pointer-like types</td>
841<td><a href="http://en.cppreference.com/w/cpp/memory/pointer_traits">std::pointer_traits</a></td>
842<td>Useful for determining the element type pointed at by a (possibly smart) pointer.</td>
Nico Weber019d40f2014-09-23 20:21:59843</tr>
844
845<tr>
846<td>Random Number Generators</td>
847<td>Functions within <code>&lt;random&gt;</code></td>
848<td>Random number generation algorithms and utilities</td>
pkasting07c0959a2016-04-14 22:16:43849<td><a href="http://en.cppreference.com/w/cpp/numeric/random">Pseudo-random number generation</a></td>
Nico Weber019d40f2014-09-23 20:21:59850<td></td>
851</tr>
852
853<tr>
854<td>Ratio Template Class</td>
855<td><code>std::ratio&lt;<i>numerator</i>, <i>denominator</i>&gt;</code></td>
856<td>Provides compile-time rational numbers</td>
pkasting07c0959a2016-04-14 22:16:43857<td><a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio">std::ratio</a></td>
858<td>Banned in <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns that they are tied to a more template-heavy interface style.</td>
Nico Weber019d40f2014-09-23 20:21:59859</tr>
860
861<tr>
862<td>Reference Wrapper Classes</td>
pkasting07c0959a2016-04-14 22:16:43863<td><code>std::reference_wrapper</code> and <code>std::ref()</code>, <code>std::cref()</code></td>
864<td>Allows you to wrap a reference within a standard object (and use those within containers)</td>
pkasting7f0693b32016-10-31 20:27:50865<td><a href="http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper">std::reference_wrapper</a></td>
Nico Weber019d40f2014-09-23 20:21:59866<td></td>
867</tr>
868
869<tr>
Nico Weber019d40f2014-09-23 20:21:59870<td>Soft Program Exits</td>
pkasting07c0959a2016-04-14 22:16:43871<td><code>std::at_quick_exit()</code>, <code>std::quick_exit()</code></td>
872<td>Allows registration of functions to be called upon exit, allowing cleaner program exit than <code>abort()</code> or <code>exit</code></td>
873<td><a href="http://en.cppreference.com/w/cpp/utility/program/quick_exit">std:quick_exit</a></td>
Nico Weber019d40f2014-09-23 20:21:59874<td></td>
875</tr>
876
877<tr>
dcheng2d4220ae2016-07-26 08:58:46878<td>String-Number Conversion Functions</td>
pkasting07c0959a2016-04-14 22:16:43879<td><code>std::stoi()</code>, <code>std::stol()</code>, <code>std::stoul()</code>, <code>std::stoll</code>, <code>std::stoull()</code>, <code>std::stof()</code>, <code>std::stod()</code>, <code>std::stold()</code>, <code>std::to_string()</code></td>
dcheng2d4220ae2016-07-26 08:58:46880<td>Converts strings to/from numbers</td>
881<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/stol">std::stoi, std::stol, std::stoll</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/stoul">std::stoul, std::stoull</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/stof">std::stof, std::stod, std::stold</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/to_string">std::to_string</a></td>
Nico Weber019d40f2014-09-23 20:21:59882<td></td>
883</tr>
884
885<tr>
Nico Weber019d40f2014-09-23 20:21:59886<td>System Errors</td>
887<td><code>&lt;system_error&gt;</code></td>
888<td>Provides a standard system error library</td>
pkasting7f0693b32016-10-31 20:27:50889<td><a href="http://en.cppreference.com/w/cpp/header/system_error">Standard library header &lt;system_error&gt;</a></td>
Nico Weber019d40f2014-09-23 20:21:59890<td></td>
891</tr>
892
893<tr>
Nico Weber019d40f2014-09-23 20:21:59894<td>Type-Generic Math Functions</td>
pkasting7f0693b32016-10-31 20:27:50895<td><code>&lt;ctgmath&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:43896<td>Provides a means to call real or complex functions based on the type of arguments</td>
897<td><a href="http://en.cppreference.com/w/cpp/header/ctgmath">Standard library header &lt;ctgmath&gt;</a></td>
Nico Weber019d40f2014-09-23 20:21:59898<td></td>
899</tr>
900
901<tr>
902<td>Type Info Enhancements</td>
pkasting07c0959a2016-04-14 22:16:43903<td><code>std::type_index</code>, <code>std::type_info::hash_code()</code></td>
904<td>Allows type information (most often within containers) that can be copied, assigned, or hashed</td>
905<td><a href="http://en.cppreference.com/w/cpp/types/type_index">std::type_index</a>, <a href="http://en.cppreference.com/w/cpp/types/type_info/hash_code">std::type_info::hash_code</a></td>
906<td><code>std::type_index</code> is a thin wrapper for <code>std::type_info</code>, allowing you to use it directly within both associative and unordered containers</td>
Nico Weber019d40f2014-09-23 20:21:59907</tr>
908
909<tr>
Nico Weber019d40f2014-09-23 20:21:59910<td>Variadic Copy Macro</td>
911<td><code>va_copy(va_list <i>dest</i>, va_list <i>src</i>)</code></td>
912<td>Makes a copy of the variadic function arguments</td>
pkasting7f0693b32016-10-31 20:27:50913<td><a href="http://en.cppreference.com/w/cpp/utility/variadic/va_copy">va_copy</a></td>
Nico Weber019d40f2014-09-23 20:21:59914<td></td>
915</tr>
916
917<tr>
918<td>Weak Pointers</td>
919<td><code>std::weak_ptr</code></td>
920<td>Allows a weak reference to a <code>std::shared_ptr</code></td>
pkasting07c0959a2016-04-14 22:16:43921<td><a href="http://en.cppreference.com/w/cpp/memory/weak_ptr">std::weak_ptr</a></td>
922<td><a href="https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers">Ownership and Smart Pointers</a></td>
Nico Weber019d40f2014-09-23 20:21:59923</tr>
924
925<tr>
926<td>Wide String Support</td>
pkasting07c0959a2016-04-14 22:16:43927<td><code>std::wstring_convert</code>, <code>std::wbuffer_convert</code><br />
928<code>std::codecvt_utf8</code>, <code>std::codecvt_utf16</code>, <code>std::codecvt_utf8_utf16</code></td>
Nico Weber019d40f2014-09-23 20:21:59929<td>Converts between string encodings</td>
pkasting07c0959a2016-04-14 22:16:43930<td><a href="http://en.cppreference.com/w/cpp/locale/wstring_convert">std::wstring_convert</a>, <a href="http://en.cppreference.com/w/cpp/locale/wbuffer_convert">std::wbuffer_convert</a>, <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8">std::codecvt_utf8</a>, <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf16">std::codecvt_utf16</a>, <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16">std::codecvt_utf8_utf16</a></td>
931<td>Non-UTF-8 text is banned by the <a href="https://google.github.io/styleguide/cppguide.html#Non-ASCII_Characters">Google Style Guide</a>. However, may be useful for consuming non-ASCII data.</td>
Nico Weber019d40f2014-09-23 20:21:59932</tr>
933
934</tbody>
935</table>
936
Nico Weber019d40f2014-09-23 20:21:59937</div>
938</body>
939</html>