blob: 3227676cc3c6218840c16e3ccfd28c118ea35922 [file] [log] [blame]
Peter Kastingf14755a2018-01-12 19:30:221<!DOCTYPE html>
Nico Weber019d40f2014-09-23 20:21:592<!--
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">
Nico Weber81c1feb2017-07-31 03:25:1310<title>C++11 and C++14 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">
Nico Weber81c1feb2017-07-31 03:25:1321<h1>C++11 and C++14 use in Chromium</h1>
Nico Weber019d40f2014-09-23 20:21:5922
23<p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium
pkastingfc30cf42016-11-04 00:49:0324checkout and is part of the more general
25<a href="https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md">
26Chromium C++ style guide</a>.</i></p>
Nico Weber019d40f2014-09-23 20:21:5927
Nico Weber81c1feb2017-07-31 03:25:1328<p>This summarizes the new and updated features in C++11 and C++14 (for both
29the language itself and the Standard Library) from the perspective of what's
30allowed in Chromium. When applicable, it contains pointers to more detailed
31information. This Guide applies to Chromium and its subprojects, though
32subprojects can choose to be more restrictive if necessary for toolchain
33support.</p>
Nico Weber019d40f2014-09-23 20:21:5934
pkastingfc30cf42016-11-04 00:49:0335<p>You can propose changing the status of a feature by sending an email to
36<a href="https://groups.google.com/a/chromium.org/forum/#!forum/cxx">
37[email protected]</a>. Include a short blurb on what the feature is and why you
38think it should or should not be allowed, along with links to any relevant
39previous discussion. If the list arrives at some consensus, send a codereview to
40change this file accordingly, linking to your discussion thread.</p>
Nico Weber019d40f2014-09-23 20:21:5941
danakj4fd49fe42015-11-18 20:54:1642<h2>Table of Contents</h2>
43<ol class="toc">
44<li>Allowed Features<ol>
Nico Weber81c1feb2017-07-31 03:25:1345 <li>Language
46 <a href="#core-whitelist">C++11</a>
47 <a href="#core-whitelist-14">C++14</a>
48 </li>
49 <li>Library
50 <a href="#library-whitelist">C++11</a>
51 <a href="#library-whitelist-14">C++14</a>
52 </li>
danakj4fd49fe42015-11-18 20:54:1653</ol></li>
54<li>Banned Features<ol>
Nico Weber81c1feb2017-07-31 03:25:1355 <li>Language
56 <a href="#core-blacklist">C++11</a>
57 <a href="#core-blacklist-14">C++14</a>
58 </li>
59 <li>Library
60 <a href="#library-blacklist">C++11</a>
61 <a href="#library-blacklist-14">C++14</a>
62 </li>
danakj4fd49fe42015-11-18 20:54:1663</ol></li>
64<li>To Be Discussed<ol>
Nico Weber81c1feb2017-07-31 03:25:1365 <li>Language
66 <a href="#core-review">C++11</a>
67 <a href="#core-review-14">C++14</a>
68 </li>
69 <li>Library
70 <a href="#library-review">C++11</a>
71 <a href="#library-review-14">C++14</a>
72 </li>
danakj4fd49fe42015-11-18 20:54:1673</ol></li>
74</ol>
75
76<h2 id="whitelist"><a name="core-whitelist"></a>C++11 Allowed Features</h2>
Nico Weber019d40f2014-09-23 20:21:5977
78<p>The following features are currently allowed.</p>
79
80<table id="whitelist_lang_list" class="unlined striped">
81<tbody>
82
83<tr>
84<th style='width:220px;'>Feature</th>
85<th style='width:260px;'>Snippet</th>
86<th style='width:240px;'>Description</th>
87<th style='width:240px;'>Documentation Link</th>
88<th style='width:240px;'>Notes and Discussion Thread</th>
89</tr>
90
91<tr>
pkastingf5279482016-07-27 02:18:2092<td>__func__ Local Variable</td>
93<td><code>__func__</code></td>
94<td>Provides a local variable containing the name of the enclosing function</td>
pkasting7f0693b32016-10-31 20:27:5095<td><a href="http://en.cppreference.com/w/cpp/language/function#func">__func__</a></td>
pkastingf5279482016-07-27 02:18:2096<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>
97</tr>
98
99<tr>
brettw16289b3e2017-06-13 21:58:40100<td>Alignment Features</td>
101<td><code>alignas(alignof(T)) char[10];</code></td>
102<td>Specifies or queries storage alignment.</td>
103<td><a href="http://en.cppreference.com/w/chttp://en.cppreference.com/w/cpp/language/alignas">alignas</a>, <a href="http://en.cppreference.com/w/cpp/language/alignof">alignof</a></td>
104<td><code>alignof()</code> can be used. <code>alignas()</code> must be used with care because it does not interact well with export and packing specifiers. If your declaration contains any other attributes, use <code>ALIGNAS()</code> from <code>base/compiler_specific.h</code> instead. <a href="https://codereview.chromium.org/2670873002/">Patch where this was discussed</a></td>
105</tr>
106
107<tr>
Nico Weber019d40f2014-09-23 20:21:59108<td>Angle Bracket Parsing in Templates</td>
pkasting07c0959a2016-04-14 22:16:43109<td><code>&gt;&gt;</code> for <code>&gt; &gt;</code>, <code>&lt;::</code> for <code>&lt; ::</code></td>
Nico Weber019d40f2014-09-23 20:21:59110<td>More intuitive parsing of template parameters</td>
pkasting7f0693b32016-10-31 20:27:50111<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:59112<td>Recommended to increase readability. Approved without discussion.</td>
113</tr>
114
115<tr>
ericrk491cd202015-12-01 01:09:16116<td>Arrays</td>
117<td><code>std::array</code></td>
118<td>A fixed-size replacement for built-in arrays, with STL support</td>
pkasting07c0959a2016-04-14 22:16:43119<td><a href="http://en.cppreference.com/w/cpp/container/array">std::array</a></td>
pkasting0cb5bd42016-11-02 20:55:58120<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>
ericrk491cd202015-12-01 01:09:16121</tr>
122
123<tr>
Nico Weber3537d872014-09-25 19:10:04124<td>Automatic Types</td>
125<td><code>auto</code></td>
126<td>Automatic type deduction</td>
pkasting07c0959a2016-04-14 22:16:43127<td><a href="http://en.cppreference.com/w/cpp/language/auto">auto specifier</a></td>
vmpstr1ccc7642017-02-14 22:06:00128<td>General guidance in <a href="https://google.github.io/styleguide/cppguide.html#auto">Google Style Guide</a>. Additionally, do not use <code>auto</code> to deduce a raw pointer, use <code>auto*</code> instead. <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:04129</tr>
130
131<tr>
pkastingce246fa2016-04-14 17:54:08132<td>Constant Expressions</td>
133<td><code>constexpr</code></td>
134<td>Compile-time constant expressions</td>
135<td><a href="http://en.cppreference.com/w/cpp/language/constexpr">constexpr specifier</a></td>
pkasting0cb5bd42016-11-02 20:55:58136<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>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/BE9xLUI-Vww">Discussion thread</a></td>
pkastingce246fa2016-04-14 17:54:08137</tr>
138
139<tr>
thakis12bfc742014-10-28 04:37:49140<td>Declared Type Accessor</td>
141<td><code>decltype(<i>expression</i>)</code></td>
pkasting07c0959a2016-04-14 22:16:43142<td>Provides a means to determine the type of an expression at compile-time, useful most often in templates.</td>
143<td><a href="http://en.cppreference.com/w/cpp/language/decltype">decltype specifier</a></td>
thakis12bfc742014-10-28 04:37:49144<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/_zoNvZd_dSo">Discussion thread</a></td>
145</tr>
146
147<tr>
mdempsky2319bef2014-11-07 05:25:12148<td>Default Function Creation</td>
149<td><code><i>Function</i>(<i>arguments</i>) = default;</code></td>
pkasting07c0959a2016-04-14 22:16:43150<td>Instructs the compiler to generate a default version of the indicated function</td>
151<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>
152<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:12153</tr>
154
155<tr>
vmpstrfcdc338e2015-12-09 19:51:08156<td>Default Function Template Arguments</td>
pkasting07c0959a2016-04-14 22:16:43157<td><code>template &lt;typename T = <i>type</i>&gt;<br />
158<i>type</i> <i>Function</i>(T <i>var</i>) {}</code></td>
vmpstrfcdc338e2015-12-09 19:51:08159<td>Allow function templates, like classes, to have default arguments</td>
pkasting07c0959a2016-04-14 22:16:43160<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:08161<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/9KtaAsome-o">Discussion thread</a></td>
162</tr>
163
164<tr>
andersr127772e2014-11-07 17:02:52165<td>Delegated Constructors</td>
pkasting07c0959a2016-04-14 22:16:43166<td><code>Class() : Class(0) {}<br />
167Class(<i>type</i> <i>var</i>) : Class(<i>var</i>, 0) {}</code></td>
andersr127772e2014-11-07 17:02:52168<td>Allow overloaded constructors to use common initialization code</td>
pkasting07c0959a2016-04-14 22:16:43169<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:52170<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/0zVA8Ctx3Xo">Discussion thread</a></td>
171</tr>
172
173<tr>
thakisb8fbe312014-10-29 01:30:42174<td>Enumerated Type Classes and Enum Bases</td>
pkasting07c0959a2016-04-14 22:16:43175<td><code>enum class <i>classname</i><br />
176enum class <i>classname</i> : <i>base-type</i><br />
177enum <i>enumname</i> : <i>base-type</i></code></td>
178<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:50179<td><a href="http://en.cppreference.com/w/cpp/language/enum">enumeration declaration</a></td>
Matt Muellere0bab0b52017-09-06 01:51:12180<td>Enum classes are still enums and follow enum naming rules. <a href="https://google.github.io/styleguide/cppguide.html#Enumerator_Names">Google 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:27181</tr>
182
183<tr>
jbromane18d31482016-04-13 18:06:47184<td>Explicit Conversion Operators</td>
pkasting07c0959a2016-04-14 22:16:43185<td><code>explicit operator <i>type</i>() { ... }</code></td>
jbromane18d31482016-04-13 18:06:47186<td>Allows conversion operators that cannot be implicitly invoked</td>
pkasting07c0959a2016-04-14 22:16:43187<td><a href="http://en.cppreference.com/w/cpp/language/explicit">explicit specifier</a></td>
pkasting0cb5bd42016-11-02 20:55:58188<td>Prefer to the "safe bool" idiom. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zGF1SrQ-1HQ">Discussion thread</a></td>
jbromane18d31482016-04-13 18:06:47189</tr>
190
191<tr>
dcheng5f98d332014-09-24 22:12:10192<td>Final Specifier</td>
193<td><code>final</code></td>
194<td> Indicates that a class or function is final and cannot be overridden</td>
pkasting7f0693b32016-10-31 20:27:50195<td><a href="http://en.cppreference.com/w/cpp/language/final">final specifier</a></td>
pkasting07c0959a2016-04-14 22:16:43196<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:10197</tr>
198
199<tr>
mdempsky2319bef2014-11-07 05:25:12200<td>Function Suppression</td>
201<td><code><i>Function</i>(<i>arguments</i>) = delete;</code></td>
pkasting07c0959a2016-04-14 22:16:43202<td>Suppresses the implementation of a function, especially a synthetic function such as a copy constructor</td>
pkasting7f0693b32016-10-31 20:27:50203<td><a href="http://en.cppreference.com/w/cpp/language/function#Deleted_functions">Deleted functions</a></td>
mdempsky2319bef2014-11-07 05:25:12204<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/i1o7-RNRnMs">Discussion thread</a></td>
205</tr>
206
207<tr>
pkasting3e35c532016-11-03 22:54:14208<td>Inherited Constructors</td>
209<td><code>class Derived : Base {<br />
210&nbsp;&nbsp;using Base::Base;<br />
211};</code></td>
212<td>Allows derived classes to inherit constructors from base classes</td>
213<td><a href="http://en.cppreference.com/w/cpp/language/using_declaration#Inheriting_constructors">Inheriting constructors</a></td>
214<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/BULzgIKZ-Ao">Discussion thread</a></td>
215</tr>
216
217<tr>
thakisa907c312014-11-04 23:38:06218<td>Lambda Expressions</td>
219<td><code>[<i>captures</i>](<i>params</i>) -&gt; <i>ret</i> { <i>body</i> }</code></td>
220<td>Anonymous functions</td>
221<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
pkasting0cb5bd42016-11-02 20:55:58222<td>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>. Be careful with default captures (<code>[=]</code>, <code>[&amp;]</code>), and do not bind or store any capturing lambdas outside the lifetime of the stack frame they are defined in; use <code>base::Callback</code> for this instead, as it helps prevent object lifetime mistakes. (Captureless lambdas can be used with <code>base::Bind</code> as they do not have the same risks.) <a href="https://google.github.io/styleguide/cppguide.html#Lambda_expressions">Google Style Guide</a>. <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">Another discussion thread</a> (about captureless lambdas and <code>base::Bind</code>).</td>
thakisa907c312014-11-04 23:38:06223</tr>
224
225<tr>
Nico Weber019d40f2014-09-23 20:21:59226<td>Local Types as Template Arguments</td>
pkasting0fcb7762016-04-29 00:44:37227<td><code>void func() {<br />
228&nbsp;&nbsp;class Pred {<br />
229&nbsp;&nbsp;&nbsp;public:<br />
brettw9efba0cd2017-03-29 20:49:41230&nbsp;&nbsp;&nbsp;&nbsp;bool operator()(const T&amp;) { ... }<br />
pkasting0fcb7762016-04-29 00:44:37231&nbsp;&nbsp;};<br />
232&nbsp;&nbsp;std::remove_if(vec.begin(), vec.end(), Pred());</code></td>
Nico Weber019d40f2014-09-23 20:21:59233<td>Allows local and unnamed types as template arguments</td>
pkasting07c0959a2016-04-14 22:16:43234<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:59235<td>Usage should be rare. Approved without discussion.</td>
236</tr>
237
238<tr>
pkastingc6a6ebf12016-10-31 20:38:40239<td>Noexcept Specifier</td>
240<td><code>void f() noexcept</code></td>
241<td>Specifies that a function will not throw exceptions</td>
242<td><a href="http://en.cppreference.com/w/cpp/language/noexcept_spec">noexcept specifier</a></td>
brettw9efba0cd2017-03-29 20:49:41243<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. Use noexcept for move constructors whenever possible (see "Notes" section on <a href="http://en.cppreference.com/w/cpp/language/move_constructor">move constructors</a>). Other usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
pkastingc6a6ebf12016-10-31 20:38:40244</tr>
245
246<tr>
hashimoto42a14e862015-01-22 15:21:41247<td>Non-Static Class Member Initializers</td>
pkasting07c0959a2016-04-14 22:16:43248<td><code>class C {<br />
249&nbsp;&nbsp;<i>type</i> <i>var</i> = <i>value</i>;<br />
250&nbsp;&nbsp;C()&nbsp;&nbsp;// copy-initializes <i>var</i></code>
hashimoto42a14e862015-01-22 15:21:41251<td>Allows non-static class members to be initialized at their definitions (outside constructors)</td>
pkasting07c0959a2016-04-14 22:16:43252<td><a href="http://en.cppreference.com/w/cpp/language/data_members">Non-static data members</a></td>
253<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:41254</tr>
255
256<tr>
danakj8bc9fc12014-09-24 20:45:29257<td>Null Pointer Constant</td>
258<td><code>nullptr</code></td>
259<td>Declares a type-safe null pointer</td>
pkasting7f0693b32016-10-31 20:27:50260<td><a href="http://en.cppreference.com/w/cpp/language/nullptr">nullptr, the pointer literal</a></td>
pkasting0cb5bd42016-11-02 20:55:58261<td>Prefer over <code>NULL</code> or <code>0</code>. <a href="https://google.github.io/styleguide/cppguide.html#0_and_nullptr/NULL">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/4mijeJHzxLg">Discussion thread</a></td>
danakj8bc9fc12014-09-24 20:45:29262</tr>
263
dcheng5f98d332014-09-24 22:12:10264<tr>
265<td>Override Specifier</td>
266<td><code>override</code></td>
267<td>Indicates that a class or function overrides a base implementation</td>
pkasting7f0693b32016-10-31 20:27:50268<td><a href="http://en.cppreference.com/w/cpp/language/override">override specifier</a></td>
pkasting07c0959a2016-04-14 22:16:43269<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:10270</tr>
271
272<tr>
Nico Weber3537d872014-09-25 19:10:04273<td>Range-Based For Loops</td>
274<td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td>
pkasting07c0959a2016-04-14 22:16:43275<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>
276<td><a href="http://en.cppreference.com/w/cpp/language/range-for">Range-based for loop</a></td>
brettw9efba0cd2017-03-29 20:49:41277<td>As a rule of thumb, use <code>for (const auto&amp; ...)</code>, <code>for (auto&amp; ...)</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>
Nico Weber3537d872014-09-25 19:10:04278</tr>
279
280<tr>
Jeremy Romanf4cca362017-11-23 18:33:35281<td>Raw String Literals</td>
282<td><code>string <i>var</i>=R&quot;(<i>raw_string</i>)&quot;;</code></td>
283<td>Allows a string to be encoded without any escape sequences, easing parsing in regex expressions, for example</td>
284<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
285<td>Beware of passing these as macro arguments, which can trigger a <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824">lexer bug</a> on older GCC versions. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
286</tr>
287
288<tr>
danakj2c5aee92015-12-07 20:40:27289<td>Rvalue References</td>
pkasting07c0959a2016-04-14 22:16:43290<td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)<br/><br/>
brettw9efba0cd2017-03-29 20:49:41291template &lt;typename T&gt;<br/>void Function(T&amp;&amp; t) { ... }</code></td>
danakj2c5aee92015-12-07 20:40:27292<td>Reference that only binds to a temporary object</td>
pkasting7f0693b32016-10-31 20:27:50293<td><a href="http://en.cppreference.com/w/cpp/language/reference#Rvalue_references">Rvalue references</a></td>
pkasting0cb5bd42016-11-02 20:55:58294<td>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://google.github.io/styleguide/cppguide.html#Rvalue_references">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/UnRaORb4TSw">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Q526tkruXpM">Another discussion thread</a></td>
danakj2c5aee92015-12-07 20:40:27295</tr>
296
297<tr>
dcheng5f98d332014-09-24 22:12:10298<td>Standard Integers</td>
pkasting07c0959a2016-04-14 22:16:43299<td>Typedefs within <code>&lt;stdint.h&gt;</code> and <code>&lt;inttypes&gt;</code></td>
dcheng5f98d332014-09-24 22:12:10300<td>Provides fixed-size integers independent of platforms</td>
pkasting7f0693b32016-10-31 20:27:50301<td><a href="http://en.cppreference.com/w/cpp/header/cstdint">Standard library header &lt;cstdint&gt;</a></td>
pkasting0cb5bd42016-11-02 20:55:58302<td>Approved without discussion. Required by the <a href="http://google.github.io/styleguide/cppguide.html#Integer_Types">Google Style Guide</a>.</td>
dcheng5f98d332014-09-24 22:12:10303</tr>
304
Nico Weber3537d872014-09-25 19:10:04305<tr>
306<td>Static Assertions</td>
307<td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td>
308<td>Tests compile-time conditions</td>
309<td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Assertion</a></td>
310<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/POISBQEhGzU">Discussion thread</a></td>
311</tr>
312
313<tr>
mikhail.pozdnyakovbac797052016-05-16 15:48:10314<td>Trailing Return Types</td>
brettw9efba0cd2017-03-29 20:49:41315<td><code>auto <i>function declaration</i> -&gt; <i>return_type</i></code></td>
mikhail.pozdnyakovbac797052016-05-16 15:48:10316<td>Allows trailing function return value syntax</td>
317<td><a href="http://en.cppreference.com/w/cpp/language/function">Declaring functions</a></td>
pkasting0cb5bd42016-11-02 20:55:58318<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>
mikhail.pozdnyakovbac797052016-05-16 15:48:10319</tr>
320
321<tr>
pkasting7f0693b32016-10-31 20:27:50322<td>Type Aliases ("using" instead of "typedef")</td>
323<td><code>using <i>new_alias</i> = <i>typename</i></code></td>
324<td>Allows parameterized typedefs</td>
325<td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias, alias template</a></td>
326<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>
327</tr>
328
329<tr>
pkasting0fcb7762016-04-29 00:44:37330<td>Uniform Initialization Syntax</td>
331<td><code><i>type</i> <i>name</i> {[<i>value</i> ..., <i>value</i>]};</code></td>
332<td>Allows any object of primitive, aggregate or class type to be initialized using brace syntax</td>
333<td><a href="http://www.stroustrup.com/C++11FAQ.html#uniform-init">Uniform initialization syntax and semantics</a></td>
334<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>
335</tr>
336
337<tr>
kwiberg882859a2016-08-16 09:42:21338<td>Union Class Members</td>
339<td><code>union <i>name</i> {<i>class</i> <i>var</i>}</code></td>
340<td>Allows class type members</td>
pkasting7f0693b32016-10-31 20:27:50341<td><a href="http://en.cppreference.com/w/cpp/language/union">Union declaration</a></td>
pkasting0cb5bd42016-11-02 20:55:58342<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/3oK78s1ntgU">Discussion thread</a></td>
kwiberg882859a2016-08-16 09:42:21343</tr>
344
345<tr>
Nico Weber3537d872014-09-25 19:10:04346<td>Variadic Macros</td>
347<td><code>#define <i>MACRO</i>(...) <i>Impl</i>(<i>args</i>, __VA_ARGS__)</code></td>
348<td>Allows macros that accept a variable number of arguments</td>
pkasting07c0959a2016-04-14 22:16:43349<td><a href="http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard">Are Variadic macros nonstandard?</a></td>
Nico Weber3537d872014-09-25 19:10:04350<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/sRx9j3CQqyA">Discussion thread</a></td>
351</tr>
352
353<tr>
354<td>Variadic Templates</td>
355<td><code>template &lt;<i>typename</i> ... <i>arg</i>&gt;</code></td>
356<td>Allows templates that accept a variable number of arguments</td>
pkasting07c0959a2016-04-14 22:16:43357<td><a href="http://en.cppreference.com/w/cpp/language/parameter_pack">Parameter pack</a></td>
avi906dbd5c2014-09-26 22:11:42358<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:04359</tr>
360
Nico Weber019d40f2014-09-23 20:21:59361</tbody>
362</table>
363
Nico Weber81c1feb2017-07-31 03:25:13364<h2 id="whitelist"><a name="core-whitelist-14"></a>C++14 Allowed Features</h2>
365
Justin Schuha4bb9652017-10-02 20:17:55366<p>The following features are currently allowed.</p>
Nico Weber81c1feb2017-07-31 03:25:13367
Nico Weber81c1feb2017-07-31 03:25:13368<table id="whitelist_lang_list_14" class="unlined striped">
369<tbody>
370
371<tr>
372<th style='width:220px;'>Feature</th>
373<th style='width:260px;'>Snippet</th>
374<th style='width:240px;'>Description</th>
375<th style='width:240px;'>Documentation Link</th>
376<th style='width:240px;'>Notes and Discussion Thread</th>
377</tr>
378
Justin Schuha4bb9652017-10-02 20:17:55379<tr>
Peter Kastingf480c8c2018-01-18 23:04:34380<td>Aggregate member initialization</td>
381<td><code>struct Point { int x, y, z = 0; };<br>Point p = {2, 3};</code></td>
382<td>Allows classes with default member initializers to be initialized with aggregate initialization, optionally omitting data members with such initializers.</td>
383<td><a href="http://en.cppreference.com/w/cpp/language/aggregate_initialization">aggregate initialization</a></td>
384<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/WMBs3K9OQ_E/discussion">Discussion thread</a></td>
385</tr>
386
387<tr>
Peter Kasting8f3f15c32018-01-19 02:53:08388<td>Binary literals</td>
389<td><code>int i = 0b1001;</code></td>
390<td>Allows defining literals in base two.</td>
391<td><a href="http://en.cppreference.com/w/cpp/language/integer_literal">Integer literals</a></td>
392<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/zsGhgaKLmIk/discussion">Discussion thread</a></td>
393</tr>
394
395<tr>
Peter Kastingc2f8749bf2018-03-31 03:32:37396<td>Function return type deduction</td>
397<td><code>auto f() { return 42; }<br>decltype(auto) g() { return 42; }</code></td>
398<td>Allows the return type of a function to be automatically deduced from its return statements, according to either template or <code>decltype</code> rules.</td>
399<td><a href="http://en.cppreference.com/w/cpp/language/function#Return_type_deduction">Return type deduction</a></td>
400<td>Usage should be rare, primarily for abstract template code. If you're not sure of the difference, prefer decltype(auto) for templated forwarding/wrapper functions and auto for other cases; see Effective Modern C++ item 3 for more detail. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/-Ox7YgRS_no/discussion">Discussion thread</a></td>
Peter Kasting8f3f15c32018-01-19 02:53:08401</tr>
402
403<tr>
Peter Kasting9cd73b922018-03-30 02:51:37404<td>Generic lambdas</td>
405<td><code>[](const auto&amp; x) { <i>...</i> }</code></td>
406<td>Allows lambda argument types to be deduced using <code>auto</code> (according to the rules that apply to templates).</td>
407<td><a href="http://en.cppreference.com/w/cpp/language/lambda">lambda expressions</a></td>
408<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/LasGKwE3SFM/discussion">Discussion thread</a></td>
409</tr>
410
411<tr>
Peter Kastingc2f8749bf2018-03-31 03:32:37412<td>Number literal separators</td>
413<td><code>float f = 1'000'000.000'1;</code></td>
414<td><code>'</code>s anywhere in int or float literals are ignored</td>
415<td><a href="http://en.cppreference.com/w/cpp/language/integer_literal">Integer literals</a>, <a href="http://en.cppreference.com/w/cpp/language/floating_literal">Floating point literals</a></td>
416<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/exS1aGs1wes/discussion">Discussion thread</a></td>
417</tr>
418
419<tr>
Justin Schuha4bb9652017-10-02 20:17:55420<td>Relaxed constant expressions</td>
421<td><code>constexpr int Factorial(int n) {<br>&nbsp;&nbsp;int result = 1;<br>&nbsp;&nbsp;while (n > 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;result *= n--;<br>&nbsp;&nbsp;return result;<br>}</code></td>
422<td>Allows use of more declarations, conditional statements and loops inside <code>constexpr</code> functions.</td>
423<td><a href="http://en.cppreference.com/w/cpp/language/constexpr">constexpr specifier</a></td>
424<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>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Psuq_EKJBAo">Discussion thread</a></td>
425</tr>
426
Nico Weber81c1feb2017-07-31 03:25:13427</tbody>
428</table>
Nico Weber81c1feb2017-07-31 03:25:13429
danakj4fd49fe42015-11-18 20:54:16430<h2 id="whitelist"><a name="library-whitelist"></a>C++11 Allowed Library Features</h2>
Nico Weberc8eb8ca2015-11-11 00:23:34431
432<p>The following library features are currently allowed.</p>
433
434<table id="whitelist_lib_list" class="unlined striped">
435<tbody>
436
437<tr>
438<th style='width:240px;'>Feature or Library</th>
439<th style='width:240px;'>Snippet</th>
440<th style='width:240px;'>Description</th>
441<th style='width:240px;'>Documentation Link</th>
pkasting0cb5bd42016-11-02 20:55:58442<th style='width:240px;'>Notes and Discussion Thread</th>
Nico Weberc8eb8ca2015-11-11 00:23:34443</tr>
444
445<tr>
davidben4507eaa2015-11-19 19:07:06446<td>Access to underlying <code>std::vector</code> data</td>
447<td><code>v.data()</code></td>
448<td>Returns a pointer to a <code>std::vector</code>'s underlying data, accounting for empty vectors.</td>
449<td><a href="http://en.cppreference.com/w/cpp/container/vector/data">std::vector::data</a></td>
pkasting2f966af2015-12-06 01:52:18450<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16V7fmtbzok">Discussion thread</a></td>
davidben4507eaa2015-11-19 19:07:06451</tr>
452
453<tr>
pkasting3adbbcc2016-02-04 01:52:38454<td>Algorithms</td>
455<td>All C++11 features in <code>&lt;algorithm&gt;</code>:<br/>
456<code>all_of</code>, <code>any_of</code>, <code>none_of</code><br/>
457<code>find_if_not</code><br/>
458<code>copy_if</code>, <code>copy_n</code><br/>
459<code>move</code>, <code>move_backward</code> (see note)<br/>
460<code>shuffle</code><br/>
461<code>is_partitioned</code>, <code>partition_copy</code>, <code>partition_point</code><br/>
462<code>is_sorted</code>, <code>is_sorted_until</code><br/>
463<code>is_heap</code>, <code>is_heap_until</code><br/>
464<code>minmax</code>, <code>minmax_element</code><br/>
pkasting07c0959a2016-04-14 22:16:43465<code>is_permutation<br/></td>
pkasting3adbbcc2016-02-04 01:52:38466<td>Safe and performant implementations of common algorithms</td>
pkasting7f0693b32016-10-31 20:27:50467<td><a href="http://en.cppreference.com/w/cpp/header/algorithm">Standard library header &lt;algorithm&gt;</a></td>
pkasting0cb5bd42016-11-02 20:55:58468<td>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/UJQk8S1IuHk">Discussion thread</a>. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/8WzmtYrZvQ8'>Another discussion thread</a></td>
pkasting3adbbcc2016-02-04 01:52:38469</tr>
470
471<tr>
Jeremy Roman90140ab2017-06-02 19:30:16472<td>Atomics</td>
473<td><code>&lt;atomic&gt;</code></td>
474<td>Fine-grained atomic types and operations</td>
475<td><a href="http://en.cppreference.com/w/cpp/atomic">Atomic operations library</a></td>
476<td>Direct use should be rare because the semantics are subtle. Prefer to use higher-level abstractions built on top of atomics or synchronization primitives.</td>
477</tr>
478
479<tr>
ruudab425288a2015-11-23 21:46:57480<td>Begin and End Non-Member Functions</td>
pkasting07c0959a2016-04-14 22:16:43481<td><code>std::begin()</code>, <code>std::end()</code></td>
pkastinga234a072016-02-11 01:35:53482<td>Allows use of free functions on any container, including fixed-size arrays</td>
pkasting07c0959a2016-04-14 22:16:43483<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>
pkasting0cb5bd42016-11-02 20:55:58484<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/forum/#!topic/cxx/5iFNE8P5qT4">Discussion thread</a></td>
ruudab425288a2015-11-23 21:46:57485</tr>
486
487<tr>
pkasting2f966af2015-12-06 01:52:18488<td>Conditional Type Selection</td>
pkasting07c0959a2016-04-14 22:16:43489<td><code>std::enable_if</code>, <code>std::conditional</code></td>
pkasting2f966af2015-12-06 01:52:18490<td>Enables compile-time conditional type selection</td>
pkasting07c0959a2016-04-14 22:16:43491<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:18492<td>Usage should be rare. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
493</tr>
494
495<tr>
pkastinga234a072016-02-11 01:35:53496<td>Constant Iterator Methods on Containers</td>
pkasting07c0959a2016-04-14 22:16:43497<td>E.g. <code>std::vector::cbegin()</code>, <code>std::vector::cend()</code></td>
pkastinga234a072016-02-11 01:35:53498<td>Allows more widespread use of <code>const_iterator</code></td>
pkasting07c0959a2016-04-14 22:16:43499<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>
pkasting0cb5bd42016-11-02 20:55:58500<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. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/cS83F_buqLM">Discussion thread</a></td>
pkasting07c0959a2016-04-14 22:16:43501</tr>
502
503<tr>
Peter Kastingf14755a2018-01-12 19:30:22504<td>Container Compaction Functions</td>
505<td><code>std::vector::shrink_to_fit()</code>, <code>std::deque::shrink_to_fit()</code>, <code>std::string::shrink_to_fit()</code></td>
506<td>Requests the removal of unused space in the container</td>
507<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>
508<td></td>
509</tr>
510
511<tr>
pkasting07c0959a2016-04-14 22:16:43512<td>Declared Type As Value</td>
513<td><code>std::declval&lt;<i>class</i>&gt;()</code></td>
514<td>Converts a type to a reference of the type to allow use of members of the type without constructing it in templates.</td>
515<td><a href="http://en.cppreference.com/w/cpp/utility/declval">std::declval</a></td>
516<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:34517</tr>
jsbella882f622015-11-13 02:02:14518
519<tr>
pkasting53121c42016-02-04 22:14:36520<td>Emplacement methods for containers</td>
521<td><code>emplace()</code>, <code>emplace_back()</code>, <code>emplace_front()</code>, <code>emplace_hint()</code></td>
pkasting07c0959a2016-04-14 22:16:43522<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:36523<td>E.g. <a href="http://en.cppreference.com/w/cpp/container/vector/emplace_back">std::vector::emplace_back</a></td>
jdoerrie16a737c2017-04-25 14:33:50524<td>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:36525</tr>
526
527<tr>
davidben411d3f72016-01-22 01:41:41528<td>Forwarding references</td>
529<td><code>std::forward()</code></td>
530<td>Perfectly forwards arguments (including rvalues)</td>
pkasting0fcb7762016-04-29 00:44:37531<td><a href="http://en.cppreference.com/w/cpp/utility/forward">std::forward</a></td>
pkasting0cb5bd42016-11-02 20:55:58532<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/forum/#!topic/cxx/-O7euklhSxs">Discussion thread</a>
davidben411d3f72016-01-22 01:41:41533</td>
534</tr>
535
536<tr>
pkasting0fcb7762016-04-29 00:44:37537<td>Initializer Lists</td>
538<td><code>std::initializer_list&lt;T&gt;</code></td>
539<td>Allows containers to be initialized with aggregate elements</td>
540<td><a href="http://en.cppreference.com/w/cpp/utility/initializer_list">std::initializer_list</a></td>
pkasting0cb5bd42016-11-02 20:55:58541<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. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/TQQ-L51_naM">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/UpiCpuu9UNc">Another discussion thread</a></td>
pkasting0fcb7762016-04-29 00:44:37542</tr>
543
544<tr>
jdoerrie300c9d72017-05-05 16:05:31545<td>Iterator Operators</td>
546<td><code>std::next()</code>, <code>std::prev()</code></td>
547<td>Copies an iterator and increments or decrements the copy by some value</td>
548<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>
549<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/KeHhLI-E2Ww">Discussion thread</a></td>
550</tr>
551
552<tr>
pkasting3adbbcc2016-02-04 01:52:38553<td>Math functions</td>
554<td>All C++11 features in <code>&lt;cmath&gt;</code>, e.g.:<br/>
555<code>INFINITY</code>, <code>NAN</code>, <code>FP_NAN</code><br/>
556<code>float_t</code>, <code>double_t</code><br/>
557<code>fmax</code>, <code>fmin</code>, <code>trunc</code>, <code>round</code><br/>
558<code>isinf</code>, <code>isnan</code><br/></td>
559<td>Useful for math-related code</td>
pkasting7f0693b32016-10-31 20:27:50560<td><a href="http://en.cppreference.com/w/cpp/header/cmath">Standard library header &lt;cmath&gt;</a></td>
pkasting3adbbcc2016-02-04 01:52:38561<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/P-1bFBXMeUk">Discussion thread</a></td>
562</tr>
563
564<tr>
pkasting2f966af2015-12-06 01:52:18565<td>Move Iterator Adaptor</td>
566<td><code>std::make_move_iterator()</code></td>
567<td>Wraps an iterator so that it moves objects instead of copying them.</td>
568<td><a href="http://en.cppreference.com/w/cpp/iterator/make_move_iterator">std::make_move_iterator</a></td>
pkasting0cb5bd42016-11-02 20:55:58569<td>Useful to move objects between containers that contain move-only types like <code>std::unique_ptr</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/lccnUljOHQU">Discussion thread</a></td>
vmpstrf484f722015-11-16 23:10:31570</tr>
571
vmpstrc52317f2015-11-18 08:43:26572<tr>
pkasting2f966af2015-12-06 01:52:18573<td>Move Semantics</td>
574<td><code>std::move()</code></td>
575<td>Facilitates efficient move operations</td>
pkasting0fcb7762016-04-29 00:44:37576<td><a href="http://en.cppreference.com/w/cpp/utility/move">std::move</a></td>
danakj2c5aee92015-12-07 20:40:27577<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
vmpstrc52317f2015-11-18 08:43:26578</tr>
579
580<tr>
pkasting0cb5bd42016-11-02 20:55:58581<td>Null Pointer Type</td>
582<td><code>std::nullptr_t</code></td>
583<td>Allows referencing the type of <code>nullptr</code>, e.g. in templates</td>
584<td><a href="http://en.cppreference.com/w/cpp/types/nullptr_t">std::nullptr_t</a></td>
585<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/UNaXc8R7eJ0">Discussion thread</a></td>
586</tr>
587
588<tr>
Daniel Cheng66345dd2018-09-13 03:14:01589<td>Random Number Distributions</td>
590<td>The random number distributions defined in <code>&lt;random&gt;</code> (see separate item for random number engines), e.g.:<br/>
591<code>uniform_int_distribution</code>, <code>uniform_real_distribution</code><br/>
592<code>poisson_distribution</code>, <code>gamma_distribution</code><br/>
593<code>normal_distribution</code>, <code>chi_squared_distribution</code><br/>
594</td>
595<td>Utilities for producing random distributions given a random bit generator.</td>
pkastingcb5ed942016-11-03 00:59:12596<td><a href="http://en.cppreference.com/w/cpp/numeric/random">Pseudo-random number generation</a></td>
597<td>Because the standard does not define precisely how the <code><i>xxx</i>_distribution</code> objects generate output, the same object may produce different output for the same seed across platforms, or even across different versions of the STL. Do not use these objects in any scenario where behavioral consistency is required. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/MLgK9vCE4BA">Discussion thread</a></td>
598</tr>
599
600<tr>
pkasting9022cb42016-02-05 00:08:56601<td>String Direct Reference Functions</td>
pkasting07c0959a2016-04-14 22:16:43602<td><code>std::string::front()</code>, <code>std::string::back()</code></td>
pkasting9022cb42016-02-05 00:08:56603<td>Returns a reference to the front or back of a string</td>
pkasting07c0959a2016-04-14 22:16:43604<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:56605<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/DRJuROAYCV4">Discussion thread</a></td>
606</tr>
607
608<tr>
vmpstrc52317f2015-11-18 08:43:26609<td>Type Traits</td>
pkasting3adbbcc2016-02-04 01:52:38610<td>All C++11 features in <code>&lt;type_traits&gt;</code> except for aligned storage (see separate item), e.g.:<br/>
611<code>integral_constant</code><br/>
612<code>is_floating_point</code>, <code>is_rvalue_reference</code>, <code>is_scalar</code><br/>
613<code>is_const</code>, <code>is_pod</code>, <code>is_unsigned</code><br/>
614<code>is_default_constructible</code>, <code>is_move_constructible</code>, <code>is_copy_assignable</code><br/>
pkasting07c0959a2016-04-14 22:16:43615<code>enable_if</code>, <code>conditional</code>, <code>result_of</code><br/></td>
vmpstrc52317f2015-11-18 08:43:26616<td>Allows compile-time inspection of the properties of types</td>
pkasting7f0693b32016-10-31 20:27:50617<td><a href="http://en.cppreference.com/w/cpp/header/type_traits">Standard library header &lt;type_traits&gt;</a></td>
Peter Kasting303de0b22018-01-12 19:35:49618<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
vmpstrc52317f2015-11-18 08:43:26619</tr>
620
ricea5db2dfe2015-12-04 14:26:46621<tr>
dcheng7bebfa462016-04-03 23:15:25622<td>Tuples</td>
pkasting00ebe862016-05-11 01:48:50623<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:25624<td>A fixed-size ordered collection of values of mixed types</td>
pkasting7f0693b32016-10-31 20:27:50625<td><a href="http://en.cppreference.com/w/cpp/header/tuple">Standard library header &lt;tuple&gt;</a></td>
tzikf7c47572017-04-05 21:45:03626<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/0NnCRmMY1xY">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/VA7Ej2IWS2w">Another discussion thread</a></td>
dcheng7bebfa462016-04-03 23:15:25627</tr>
628
629<tr>
davidben411d3f72016-01-22 01:41:41630<td>Unordered Associative Containers</td>
pkasting07c0959a2016-04-14 22:16:43631<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:41632<td>Allows efficient containers of key/value pairs</td>
pkasting07c0959a2016-04-14 22:16:43633<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>
pkasting0cb5bd42016-11-02 20:55:58634<td>Specify custom hashers instead of specializing <code>std::hash</code> for custom types. <a href="https://google.github.io/styleguide/cppguide.html#std_hash">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/nCdjQqnouO4">Discussion thread</a></td>
davidben411d3f72016-01-22 01:41:41635</tr>
636
tzik9ca302192016-02-11 10:24:45637<tr>
dcheng7bebfa462016-04-03 23:15:25638<td>Unique Pointers</td>
639<td><code>std::unique_ptr&lt;<i>type</i>&gt;</code></td>
640<td>A smart pointer with sole ownership of the owned object.</td>
641<td><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr">std::unique_ptr</a></td>
pkasting0cb5bd42016-11-02 20:55:58642<td><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/forum/#!topic/cxx/aT2wsBLKvzI">Discussion thread</a></td>
tzik9ca302192016-02-11 10:24:45643</tr>
644
Nico Weberc8eb8ca2015-11-11 00:23:34645</tbody>
646</table>
647
Nico Weber81c1feb2017-07-31 03:25:13648<h2 id="whitelist"><a name="library-whitelist-14"></a>C++14 Allowed Library Features</h2>
649
Nico Weber81c1feb2017-07-31 03:25:13650<p>The following library features are currently allowed.</p>
651
652<table id="whitelist_lib_list" class="unlined striped">
653<tbody>
654
655<tr>
656<th style='width:240px;'>Feature or Library</th>
657<th style='width:240px;'>Snippet</th>
658<th style='width:240px;'>Description</th>
659<th style='width:240px;'>Documentation Link</th>
660<th style='width:240px;'>Notes and Discussion Thread</th>
661</tr>
662
Jeremy Romandd41e752017-08-16 13:08:05663<tr>
Peter Kasting225a72a2018-01-12 19:53:41664<td>Constant begin/end non-member functions</td>
665<td><code>std::cbegin(<i>container</i>)<br>std::cend(<i>container</i>)<br>std::crbegin(<i>container</i>)<br>std::crend(<i>container</i>)</br></code></td>
666<td>Constant counterparts to <code>std::begin</code> etc.</td>
667<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">std::cbegin</a></td>
668<td></td>
669</tr>
670
671<tr>
Jeremy Roman863386d2017-10-31 19:25:38672<td>Heterogeneous lookup in associative containers</td>
673<td><code><i>// Does not construct an std::string to use as the lookup key.</i><br>std::map&lt;std::string, int, std::less&lt;&gt;&gt; map;<br>auto it = map.find("answer");</code></td>
674<td>Allows searching associative containers without converting the key to exactly match the stored key type, assuming a suitable comparator exists.</td>
675<td><a href="http://en.cppreference.com/w/cpp/utility/functional/less">std::less</a></td>
676<td><a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
677</tr>
678
679<tr>
Jeremy Roman84956fa2017-08-16 15:55:20680<td><code>std::integer_sequence</code></td>
681<td><code>template &lt;size_t... I&gt;<br>void CallFooImpl(std::index_sequence&lt;I...&gt;) {<br>&nbsp;&nbsp;Foo(I...);<br>}<br><br>template &lt;size_t N&gt;<br>void CallFoo() {<br>&nbsp;&nbsp;CallFooImpl(std::make_index_sequence&lt;N&gt;());<br>}</code></td>
682<td>Template metaprogramming utility for representing a sequence of integers as a type.</td>
683<td><a href="http://en.cppreference.com/w/cpp/utility/integer_sequence">std::integer_sequence</a></td>
684<td>This also includes the alias, <code>std::index_sequence</code>, which is the specialization for <code>size_t</code>. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
685</tr>
686
687<tr>
Jeremy Romandd41e752017-08-16 13:08:05688<td><code>std::make_unique</code></td>
689<td><code>auto widget = std::make_unique&lt;Widget&gt;();</code></td>
690<td>Allocates objects on the heap and immediately constructs an <code>std::unique_ptr</code> to assume ownership.</td>
691<td><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique">std::make_unique</a></td>
692<td>Should replace <code>base::MakeUnique</code> and <code>WTF::MakeUnique</code>. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
693</tr>
694
Denis Yaroshevskiy24d26d962017-08-18 13:17:32695<tr>
696<td>Transparent function objects</td>
697<td>Arithmetic operations:<br><code>std::plus&lt;&gt;, std::minus&lt;&gt;</code> ...<br>Comparisons:<br><code>std::less&lt;&gt;, std::equal_to&lt;&gt;</code>...<br>Logical operations:<br><code>std::logical_and&lt;&gt;, std::logical_or&lt;&gt;</code>...<br>Bitwise operations:<br><code>std::bit_and&lt;&gt;, std::bit_or&lt;&gt;</code>...<br></td>
698<td>Function objects that deduce argument types.</td>
699<td><a href="http://en.cppreference.com/w/cpp/utility/functional/less_void">std::less&lt;&gt;</a></td>
Peter Kasting303de0b22018-01-12 19:35:49700<td>Should replace <code>base::less</code> and usage of these functors with explicit types where appropriate. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/cPoULd2NY9k">Discussion thread</a></td>
Denis Yaroshevskiy24d26d962017-08-18 13:17:32701</tr>
702
Peter Kasting1b368e72018-01-13 01:49:52703<tr>
704<td>Tuple addressing by type</td>
705<td><code>std::tuple&lt;int, char&gt; enterprise(1701, 'D');<br>int n = std::get&lt;int&gt;(enterprise);</code></td>
706<td>Allows entries in a tuple to be accessed by type rather than entry, if it is not ambiguous.</td>
707<td><a href="http://en.cppreference.com/w/cpp/utility/tuple/get">std::get(std::tuple)</a></td>
708<td></td>
709</tr>
710
Vaclav Brozek086087242018-05-30 20:50:59711<tr>
712<td>Reverse Iterator Adaptor</td>
713<td><code>std::make_reverse_iterator()</code></td>
714<td>For a given iterator, deduces the type of a corresponding reverse iterator and constructs it.</td>
715<td><a href="http://en.cppreference.com/w/cpp/iterator/make_reverse_iterator">std::make_reverse_iterator</a></td>
716<td>Useful to reduce boilerplate when constructing reverse iterators. The alternative is using <code>std::reverse_iterator<T>(i)</code> where <code>T</code> is the, usually long, type of the iterator <code>i</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/qOE1XA0b6Dk">Discussion thread</a></td>
717</tr>
718
Nico Weber81c1feb2017-07-31 03:25:13719</tbody>
720</table>
Nico Weber81c1feb2017-07-31 03:25:13721
722<h2 id="blacklist">C++11 and C++14 Blacklist (Disallowed and Banned Features)</h2>
Nico Weber019d40f2014-09-23 20:21:59723
724<p>This section lists features that are not allowed to be used yet.
725
danakj4fd49fe42015-11-18 20:54:16726<h3 id="blacklist_banned"><a name="core-blacklist"></a>C++11 Banned Features</h3>
Nico Weber019d40f2014-09-23 20:21:59727
Peter Kasting97c52e472018-01-17 03:39:07728<p>This section lists C++11 features that are not allowed in the Chromium codebase.</p>
Nico Weber019d40f2014-09-23 20:21:59729
Nico Weber019d40f2014-09-23 20:21:59730<table id="banned_list" class="unlined striped">
731<tbody>
732
733<tr>
734<th style='width:240px;'>Feature or Library</th>
735<th style='width:240px;'>Snippet</th>
736<th style='width:240px;'>Description</th>
737<th style='width:240px;'>Documentation Link</th>
pkasting0cb5bd42016-11-02 20:55:58738<th style='width:240px;'>Notes and Discussion Thread</th>
Nico Webercea20a82014-09-25 17:46:51739</tr>
740
741<tr>
pkastingfb8e7fe2016-10-31 21:34:45742<td>Inline Namespaces</td>
743<td><code>inline namespace foo { ... }</code></td>
744<td>Allows better versioning of namespaces</td>
745<td><a href="http://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces">Inline namespaces</a></td>
746<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>
mdempsky33bafda2014-10-30 23:14:52747</tr>
748
749<tr>
thakis12bfc742014-10-28 04:37:49750<td><code>long long</code> Type</td>
pkasting7f0693b32016-10-31 20:27:50751<td><code>long long <i>var</i> = <i>value</i>;</code></td>
thakis12bfc742014-10-28 04:37:49752<td>An integer of at least 64 bits</td>
pkasting07c0959a2016-04-14 22:16:43753<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
754<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:49755</tr>
756
757<tr>
jbromand21995c52016-01-07 23:43:54758<td>Ref-qualified Member Functions</td>
pkasting07c0959a2016-04-14 22:16:43759<td><code>class T {<br />
brettw9efba0cd2017-03-29 20:49:41760&nbsp;&nbsp;void f() &amp; {}<br />
761&nbsp;&nbsp;void f() &amp;&amp; {}<br />
pkasting07c0959a2016-04-14 22:16:43762};<br />
763t.f();&nbsp;&nbsp;// first<br />
764T().f();&nbsp;&nbsp;// second<br />
765std::move(t).f();&nbsp;&nbsp;// second</code></td>
jbromand21995c52016-01-07 23:43:54766<td>Allows class member functions to only bind to |this| as an rvalue or lvalue.</td>
pkasting7f0693b32016-10-31 20:27:50767<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>
pkasting0cb5bd42016-11-02 20:55:58768<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/forum/#!topic/cxx/gowclr2LPQA">Discussion Thread</a></td>
jbromand21995c52016-01-07 23:43:54769</tr>
770
pkastingfb8e7fe2016-10-31 21:34:45771<tr>
772<td>User-Defined Literals</td>
773<td><code><i>type</i> <i>var</i> = <i>literal_value</i>_<i>type</i></code></td>
774<td>Allows user-defined literal expressions</td>
775<td><a href="http://en.cppreference.com/w/cpp/language/user_literal">User-defined literals</a></td>
776<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#Operator_Overloading">Google Style Guide</a>.</td>
777</tr>
778
Brett Wilson251bf4fc2017-08-22 19:17:07779<tr>
780<td>thread_local storage class</td>
781<td><code>thread_local int foo = 1;</code></td>
782<td>Puts variables into thread local storage.</td>
783<td><a href="http://en.cppreference.com/w/cpp/language/storage_duration">Storage duration</a></td>
784<td>Some surprising effects on Mac (<a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2msN8k3Xzgs">discussion</a>, <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/h7O5BdtWCZw">fork</a>). Use <a href="https://cs.chromium.org/chromium/src/base/threading/sequence_local_storage_slot.h">SequenceLocalStorageSlot</a> for sequence support, and <a href="https://cs.chromium.org/chromium/src/base/threading/thread_local.h">ThreadLocal</a>/<a href="https://cs.chromium.org/chromium/src/base/threading/thread_local_storage.h">ThreadLocalStorage</a> otherwise.</td>
785</tr>
786
Nico Weber019d40f2014-09-23 20:21:59787</tbody>
788</table>
Nico Weber019d40f2014-09-23 20:21:59789
Nico Weber81c1feb2017-07-31 03:25:13790<h3 id="blacklist_banned"><a name="core-blacklist-14"></a>C++14 Banned Features</h3>
791
Peter Kasting97c52e472018-01-17 03:39:07792<p>This section lists C++14 features that are not allowed in the Chromium codebase.</p>
Nico Weber81c1feb2017-07-31 03:25:13793
794<table id="banned_list" class="unlined striped">
795<tbody>
796
797<tr>
Peter Kasting321bc212018-01-12 19:33:06798<th style='width:240px;'>Feature</th>
Nico Weber81c1feb2017-07-31 03:25:13799<th style='width:240px;'>Snippet</th>
800<th style='width:240px;'>Description</th>
801<th style='width:240px;'>Documentation Link</th>
802<th style='width:240px;'>Notes and Discussion Thread</th>
803</tr>
804
Peter Kasting321bc212018-01-12 19:33:06805<tr>
Nico Weber81c1feb2017-07-31 03:25:13806</tbody>
807</table>
Nico Weber81c1feb2017-07-31 03:25:13808
danakj4fd49fe42015-11-18 20:54:16809<h3 id="blacklist_stdlib"><a name="library-blacklist"></a>C++11 Banned Library Features</h3>
Nico Weberc8eb8ca2015-11-11 00:23:34810
811<p>This section lists C++11 library features that are not allowed in the Chromium codebase.</p>
812
813<table id="blacklist_lib_list" class="unlined striped">
814<tbody>
815
816<tr>
817<th style='width:240px;'>Feature</th>
818<th style='width:240px;'>Snippet</th>
819<th style='width:240px;'>Description</th>
820<th style='width:240px;'>Documentation Link</th>
pkasting0cb5bd42016-11-02 20:55:58821<th style='width:240px;'>Notes and Discussion Thread</th>
Nico Weberc8eb8ca2015-11-11 00:23:34822</tr>
823
824<tr>
brettw16289b3e2017-06-13 21:58:40825<td>Aligned storage</td>
826<td><code>std::aligned_storage&lt;10, 128&gt;</code></td>
827<td>Uninitialized storage for objects requiring specific alignment.</td>
828<td><a href="http://en.cppreference.com/w/cpp/types/aligned_storage">std::aligned_storage</a></td>
829<td>MSVC 2017's implementation does not align on boundaries greater than sizeof(double) = 8 bytes. Use <code>alignas(128) char foo[10];</code> instead. <a href="https://codereview.chromium.org/2932053002">Patch where this was discovered</a>.</td>
830</tr>
831
pkastingfc30cf42016-11-04 00:49:03832<td>Bind Operations</td>
833<td><code>std::bind(<i>function</i>, <i>args</i>, ...)</code></td>
834<td>Declares a function object bound to certain arguments</td>
835<td><a href="http://en.cppreference.com/w/cpp/utility/functional/bind">std::bind</a></td>
836<td>Use <code>base::Bind</code> instead. Compared to <code>std::bind</code>, <code>base::Bind</code> helps prevent lifetime issues by preventing binding of capturing lambdas and by forcing callers to declare raw pointers as <code>Unretained</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
837</tr>
838
839<tr>
840<td>C Floating-Point Environment</td>
841<td><code>&lt;cfenv&gt;</code>, <code>&lt;fenv.h&gt;</code></td>
842<td>Provides floating point status flags and control modes for C-compatible code</td>
843<td><a href="http://en.cppreference.com/w/cpp/header/cfenv">Standard library header &lt;cfenv&gt;</a></td>
844<td>Banned by the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns about compiler support.</td>
845</tr>
846
847<tr>
pkasting7f0693b32016-10-31 20:27:50848<td>Date and time utilities</td>
Nico Weberc8eb8ca2015-11-11 00:23:34849<td><code>&lt;chrono&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50850<td>A standard date and time library</td>
Nico Weberc8eb8ca2015-11-11 00:23:34851<td><a href="http://en.cppreference.com/w/cpp/chrono">Date and time utilities</a></td>
pkasting7f0693b32016-10-31 20:27:50852<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:34853</tr>
854
855<tr>
pkastingc6a6ebf12016-10-31 20:38:40856<td>Exceptions</td>
857<td><code>&lt;exception&gt;</code></td>
858<td>Enhancements to exception throwing and handling</td>
859<td><a href="http://en.cppreference.com/w/cpp/header/exception">Standard library header &lt;exception&gt;</a></td>
860<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>
861</tr>
862
863<tr>
pkastingfc30cf42016-11-04 00:49:03864<td>Function Objects</td>
865<td><code>std::function</code></td>
866<td>Wraps a standard polymorphic function</td>
867<td><a href="http://en.cppreference.com/w/cpp/utility/functional/function">std::function</a></td>
868<td>Use <code>base::Callback</code> instead. Compared to <code>std::function</code>, <code>base::Callback</code> directly supports Chromium's refcounting classes and weak pointers and deals with additional thread safety concerns. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
869</tr>
870
871<tr>
Daniel Cheng66345dd2018-09-13 03:14:01872<td>Random Number Engines</td>
873<td>The random number engines defined in <code>&lt;random&gt;</code> (see separate item for random number distributions), e.g.:<br/>
874<code>linear_congruential_engine</code>, <code>mersenne_twister_engine</code><br/>
875<code>minstd_rand0</code>, <code>mt19937</code>, <code>ranlinux48</code><br/>
876<code>random_device</code>
877</td>
878<td>Random number generation algorithms and utilities.</td>
879<td><a href="http://en.cppreference.com/w/cpp/numeric/random">Pseudo-random number generation</a></td>
880<td>Do not use any random number engines from <code>&lt;random</code>. Instead, use <code>base::RandomBitGenerator</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16Xmw05C-Y0">Discussion thread</a></td>
881</tr>
882
883<tr>
pkastingfc30cf42016-11-04 00:49:03884<td>Ratio Template Class</td>
885<td><code>std::ratio&lt;<i>numerator</i>, <i>denominator</i>&gt;</code></td>
886<td>Provides compile-time rational numbers</td>
887<td><a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio">std::ratio</a></td>
888<td>Banned by the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns that this is tied to a more template-heavy interface style.</td>
889</tr>
890
891<tr>
pkasting7f0693b32016-10-31 20:27:50892<td>Regular Expressions</td>
Nico Weberc8eb8ca2015-11-11 00:23:34893<td><code>&lt;regex&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50894<td>A standard regular expressions library</td>
Nico Weberc8eb8ca2015-11-11 00:23:34895<td><a href="http://en.cppreference.com/w/cpp/regex">Regular expressions library</a></td>
pkasting7f0693b32016-10-31 20:27:50896<td>Overlaps with many regular expression libraries in Chromium. When in doubt, use re2.</td>
Nico Weberc8eb8ca2015-11-11 00:23:34897</tr>
898
899<tr>
pkastingfb8e7fe2016-10-31 21:34:45900<td>Shared Pointers</td>
901<td><code>std::shared_ptr</code></td>
902<td>Allows shared ownership of a pointer through reference counts</td>
903<td><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr">std::shared_ptr</a></td>
pkasting0cb5bd42016-11-02 20:55:58904<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/forum/#!topic/cxx/aT2wsBLKvzI">Discussion Thread</a></td>
pkastingfb8e7fe2016-10-31 21:34:45905</tr>
906
907<tr>
Nico Weberc8eb8ca2015-11-11 00:23:34908<td>Thread Library</td>
pkasting7f0693b32016-10-31 20:27:50909<td><code>&lt;thread&gt;</code> and related headers, including<br />
pkasting07c0959a2016-04-14 22:16:43910<code>&lt;future&gt;</code>, <code>&lt;mutex&gt;</code>, <code>&lt;condition_variable&gt;</code></td>
pkasting7f0693b32016-10-31 20:27:50911<td>Provides a standard multithreading library using <code>std::thread</code> and associates</td>
Nico Weberc8eb8ca2015-11-11 00:23:34912<td><a href="http://en.cppreference.com/w/cpp/thread">Thread support library</a></td>
pkasting7f0693b32016-10-31 20:27:50913<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:34914</tr>
915
916</tbody>
917</table>
918
Nico Weber81c1feb2017-07-31 03:25:13919<h3 id="blacklist_stdlib"><a name="library-blacklist-14"></a>C++14 Banned Library Features</h3>
920
Jeremy Romanabd27842017-08-04 18:27:55921<p>This section lists C++14 library features that are not allowed in the Chromium codebase.</p>
Nico Weber81c1feb2017-07-31 03:25:13922
923<table id="blacklist_lib_list" class="unlined striped">
924<tbody>
925
926<tr>
927<th style='width:240px;'>Feature</th>
928<th style='width:240px;'>Snippet</th>
929<th style='width:240px;'>Description</th>
930<th style='width:240px;'>Documentation Link</th>
931<th style='width:240px;'>Notes and Discussion Thread</th>
932</tr>
933
Jeremy Romanabd27842017-08-04 18:27:55934<tr>
935<td><code>std::chrono</code> literals</td>
936<td><code>using namespace std::chrono_literals;<br>auto timeout = 30s;</code></td>
937<td>Allows <code>std::chrono</code> types to be more easily constructed.</td>
938<td><a href="http://en.cppreference.com/w/cpp/chrono/operator%22%22s">std::literals::chrono_literals::operator""s</a></td>
939<td>Banned because <code>&lt;chrono&gt;</code> is banned.</td>
940</tr>
941
Nico Weber81c1feb2017-07-31 03:25:13942</tbody>
943</table>
Nico Weberc8eb8ca2015-11-11 00:23:34944
danakj4fd49fe42015-11-18 20:54:16945<h3 id="blacklist_review"><a name="core-review"></a>C++11 Features To Be Discussed</h3>
Nico Weber019d40f2014-09-23 20:21:59946
pkastingfc30cf42016-11-04 00:49:03947<p>The following C++ language 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.</p>
Nico Weber019d40f2014-09-23 20:21:59948
949<table id="blacklist_review_list" class="unlined striped">
950<tbody>
951
952<tr>
953<th style='width:240px;'>Feature</th>
954<th style='width:240px;'>Snippet</th>
955<th style='width:240px;'>Description</th>
956<th style='width:240px;'>Documentation Link</th>
pkasting0cb5bd42016-11-02 20:55:58957<th style='width:240px;'>Notes and Discussion Thread</th>
Nico Weber019d40f2014-09-23 20:21:59958</tr>
959
960<tr>
Nico Weber019d40f2014-09-23 20:21:59961<td>Attributes</td>
962<td><code>[[<i>attribute_name</i>]]</code></td>
pkasting07c0959a2016-04-14 22:16:43963<td>Attaches properties to declarations that specific compiler implementations may use.</td>
964<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:59965<td></td>
966</tr>
967
968<tr>
pkastingfb8e7fe2016-10-31 21:34:45969<td>UTF-8, UTF-16, UTF-32 String Literals</td>
970<td><code>u8&quot;<i>string</i>&quot;, u&quot;<i>string</i>&quot;, U&quot;<i>string</i>&quot;</code></td>
971<td>Enforces UTF-8, UTF-16, UTF-32 encoding on all string literals</td>
972<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
973<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>
974</tr>
975
976<tr>
977<td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td>
978<td><code>char16_t</code> and <code>char32_t</code></td>
979<td>Provides character types for handling 16-bit and 32-bit code units (useful for encoding UTF-16 and UTF-32 string data)</td>
980<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
981<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 Weber019d40f2014-09-23 20:21:59982</tr>
983
Nico Weber019d40f2014-09-23 20:21:59984</tbody>
985</table>
986
Nico Weber81c1feb2017-07-31 03:25:13987<h3 id="blacklist_review"><a name="core-review-14"></a>C++14 Features To Be Discussed</h3>
988
989<p>The following C++14 language 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.</p>
990
991<table id="blacklist_review_list" class="unlined striped">
992<tbody>
993
994<tr>
995<th style='width:240px;'>Feature</th>
996<th style='width:240px;'>Snippet</th>
997<th style='width:240px;'>Description</th>
998<th style='width:240px;'>Documentation Link</th>
999<th style='width:240px;'>Notes and Discussion Thread</th>
1000</tr>
1001
1002<tr>
1003<td><code>[[deprecated]]</code> attribute</td>
1004<td><code>[[deprecated]] void f();<br>
1005[[deprecated("use h() instead")]] void g();</code></td>
1006<td>Marks a function as deprecated.</td>
1007<td><a href="http://en.cppreference.com/w/cpp/language/attributes">Standard attributes</a></td>
1008<td>We don't use deprecation warnings in Chromium; if you want to deprecate
1009something, remove all callers and remove the function instead.</td>
1010</tr>
1011
1012<tr>
Jeremy Romanabd27842017-08-04 18:27:551013<td><code>decltype(auto)</code> variable declarations</td>
1014<td><code>decltype(auto) x = 42;</code></td>
1015<td>Allows deducing the type of a variable using <code>decltype</code> rules.</td>
1016<td><a href="http://en.cppreference.com/w/cpp/language/auto">auto specifier</a></td>
1017<td>Often more surprising than <code>auto</code>. For instance, the <code>decltype</code> deduction rules do not remove references.</td>
1018</tr>
1019
1020<tr>
Jeremy Romanabd27842017-08-04 18:27:551021<td>Lambda capture expressions</td>
Jeremy Roman52b84692018-03-02 15:42:371022<td><code>auto widget = std::make_unique&lt;Widget&gt;();<br>auto lambda = [widget = std::move(widget)]() {<br>&nbsp;&nbsp;SetWidget(std::move(widget));<br>}</code></td>
Jeremy Romanabd27842017-08-04 18:27:551023<td>Allows lambda captures to be explicitly initialized with expressions.</td>
1024<td><a href="http://en.cppreference.com/w/cpp/language/lambda#Lambda_capture">Lambda capture</a></td>
1025<td>Particularly useful to capture move-only types in a lambda when a reference would go out of scope. Less useful without allowing lambdas to outlive the scope.</td>
1026</tr>
1027
1028<tr>
Jeremy Romanabd27842017-08-04 18:27:551029<td>Variable templates</td>
1030<td><code>template &lt;typename T&gt;<br>constexpr T tau = T(6.283185307179586476925286766559);</code></td>
1031<td>Allows templates that declare variables, rather than functions or classes.</td>
1032<td><a href="http://en.cppreference.com/w/cpp/language/variable_template">Variable template</a></td>
1033<td></td>
1034</tr>
Nico Weber81c1feb2017-07-31 03:25:131035
1036</tbody>
1037</table>
1038
danakj4fd49fe42015-11-18 20:54:161039<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:591040
pkastingfc30cf42016-11-04 00:49:031041<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.</p>
Nico Weber019d40f2014-09-23 20:21:591042
1043<table id="banned_stdlib" class="unlined striped">
1044
1045<tbody>
1046<tr>
1047<th style='width:240px;'>Feature</th>
1048<th style='width:240px;'>Snippet</th>
1049<th style='width:240px;'>Description</th>
1050<th style='width:240px;'>Documentation Link</th>
pkasting0cb5bd42016-11-02 20:55:581051<th style='width:240px;'>Notes</th>
Nico Weber019d40f2014-09-23 20:21:591052</tr>
1053
1054<tr>
1055<td>Address Retrieval</td>
1056<td><code>std::addressof()</code></td>
1057<td>Obtains the address of an object even with overloaded <code>operator&amp;</code></td>
1058<td><a href="http://en.cppreference.com/w/cpp/memory/addressof">std::addressof</a></td>
pkasting07c0959a2016-04-14 22:16:431059<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:591060</tr>
1061
1062<tr>
1063<td>Aligned Storage</td>
brettw16289b3e2017-06-13 21:58:401064<td><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:181065<td>Declare uninitialized storage having a specified alignment, or determine alignments.</td>
brettw16289b3e2017-06-13 21:58:401066<td><a href="http://en.cppreference.com/w/cpp/types/aligned_union">std::aligned_union</a></td>
1067<td><code>std::aligned_union</code> is disallowed in google3 over concerns about compatibility with internal cross-compiling toolchains. <code>std::aligned_storage</code> is on the disallowed list due to compatibility concerns.</td>
Nico Weber019d40f2014-09-23 20:21:591068</tr>
1069
1070<tr>
1071<td>Allocator Traits</td>
1072<td><code>std::allocator_traits</code></td>
1073<td>Provides an interface for accessing custom allocators</td>
pkasting07c0959a2016-04-14 22:16:431074<td><a href="http://en.cppreference.com/w/cpp/memory/allocator_traits">std::allocator_traits</a></td>
Nico Weber019d40f2014-09-23 20:21:591075<td>Usage should be rare.</td>
1076</tr>
1077
1078<tr>
Nico Weber019d40f2014-09-23 20:21:591079<td>Complex Inverse Trigonometric and Hyperbolic Functions</td>
1080<td>Functions within <code>&lt;complex&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:431081<td>Adds inverse trigonomentric and hyperbolic non-member functions to the <code>&lt;complex&gt;</code> library.</td>
Nico Weber019d40f2014-09-23 20:21:591082<td><a href="http://en.cppreference.com/w/cpp/numeric/complex">std::complex</a></td>
1083<td></td>
1084</tr>
1085
1086<tr>
Nico Weber019d40f2014-09-23 20:21:591087<td>Date/Time String Formatting Specifiers</td>
1088<td><code>std::strftime()</code></td>
pkasting07c0959a2016-04-14 22:16:431089<td>Converts date and time information into a formatted string using new specifiers</td>
1090<td><a href="http://en.cppreference.com/w/cpp/chrono/c/strftime">std::strftime</a></td>
Nico Weber019d40f2014-09-23 20:21:591091<td></td>
1092</tr>
1093
1094<tr>
Peter Kastingc2f8749bf2018-03-31 03:32:371095<td>Function Return Type Extraction</td>
Nico Weber019d40f2014-09-23 20:21:591096<td><code>std::result_of&lt;<i>Functor(ArgTypes...)</i>&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:431097<td>Extracts the return type from the type signature of a function call invocation at compile-time.</td>
1098<td><a href="http://en.cppreference.com/w/cpp/types/result_of">std::result_of</a></td>
1099<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:591100</tr>
1101
1102<tr>
Nico Weber019d40f2014-09-23 20:21:591103<td>Forward Lists</td>
1104<td><code>std::forward_list</code></td>
1105<td>Provides an efficient singly linked list</td>
pkasting07c0959a2016-04-14 22:16:431106<td><a href="http://en.cppreference.com/w/cpp/container/forward_list">std::forward_list</a></td>
Nico Weber019d40f2014-09-23 20:21:591107<td></td>
1108</tr>
1109
1110<tr>
1111<td>Gamma Natural Log</td>
1112<td><code>std::lgamma()</code></td>
pkasting07c0959a2016-04-14 22:16:431113<td>Computes the natural log of the gamma of a floating point value</td>
1114<td><a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma">std::lgamma</a></td>
Nico Weber019d40f2014-09-23 20:21:591115<td></td>
1116</tr>
1117
1118<tr>
1119<td>Garbage Collection Features</td>
pkasting07c0959a2016-04-14 22:16:431120<td><code>std::{un}declare_reachable()</code>, <code>std::{un}declare_no_pointers()</code></td>
Nico Weber019d40f2014-09-23 20:21:591121<td>Enables garbage collection implementations</td>
pkasting07c0959a2016-04-14 22:16:431122<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:591123<td></td>
1124</tr>
1125
1126<tr>
Nico Weber019d40f2014-09-23 20:21:591127<td>Pointer Traits Class Template</td>
1128<td><code>std::pointer_traits</code></td>
pkasting07c0959a2016-04-14 22:16:431129<td>Provides a standard way to access properties of pointers and pointer-like types</td>
1130<td><a href="http://en.cppreference.com/w/cpp/memory/pointer_traits">std::pointer_traits</a></td>
1131<td>Useful for determining the element type pointed at by a (possibly smart) pointer.</td>
Nico Weber019d40f2014-09-23 20:21:591132</tr>
1133
1134<tr>
Nico Weber019d40f2014-09-23 20:21:591135<td>Reference Wrapper Classes</td>
pkasting07c0959a2016-04-14 22:16:431136<td><code>std::reference_wrapper</code> and <code>std::ref()</code>, <code>std::cref()</code></td>
1137<td>Allows you to wrap a reference within a standard object (and use those within containers)</td>
pkasting7f0693b32016-10-31 20:27:501138<td><a href="http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper">std::reference_wrapper</a></td>
Nico Weber019d40f2014-09-23 20:21:591139<td></td>
1140</tr>
1141
1142<tr>
Nico Weber019d40f2014-09-23 20:21:591143<td>Soft Program Exits</td>
pkasting07c0959a2016-04-14 22:16:431144<td><code>std::at_quick_exit()</code>, <code>std::quick_exit()</code></td>
1145<td>Allows registration of functions to be called upon exit, allowing cleaner program exit than <code>abort()</code> or <code>exit</code></td>
1146<td><a href="http://en.cppreference.com/w/cpp/utility/program/quick_exit">std:quick_exit</a></td>
Nico Weber019d40f2014-09-23 20:21:591147<td></td>
1148</tr>
1149
1150<tr>
dcheng2d4220ae2016-07-26 08:58:461151<td>String-Number Conversion Functions</td>
pkasting07c0959a2016-04-14 22:16:431152<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:461153<td>Converts strings to/from numbers</td>
1154<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>
pkasting0cb5bd42016-11-02 20:55:581155<td>May be useful to <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=593512">replace dmg_fp</a>.</td>
Nico Weber019d40f2014-09-23 20:21:591156</tr>
1157
1158<tr>
Nico Weber019d40f2014-09-23 20:21:591159<td>System Errors</td>
1160<td><code>&lt;system_error&gt;</code></td>
1161<td>Provides a standard system error library</td>
pkasting7f0693b32016-10-31 20:27:501162<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:591163<td></td>
1164</tr>
1165
1166<tr>
Nico Weber019d40f2014-09-23 20:21:591167<td>Type-Generic Math Functions</td>
pkasting7f0693b32016-10-31 20:27:501168<td><code>&lt;ctgmath&gt;</code></td>
pkasting07c0959a2016-04-14 22:16:431169<td>Provides a means to call real or complex functions based on the type of arguments</td>
1170<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:591171<td></td>
1172</tr>
1173
1174<tr>
1175<td>Type Info Enhancements</td>
pkasting07c0959a2016-04-14 22:16:431176<td><code>std::type_index</code>, <code>std::type_info::hash_code()</code></td>
1177<td>Allows type information (most often within containers) that can be copied, assigned, or hashed</td>
1178<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>
pkasting0cb5bd42016-11-02 20:55:581179<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:591180</tr>
1181
1182<tr>
Nico Weber019d40f2014-09-23 20:21:591183<td>Variadic Copy Macro</td>
1184<td><code>va_copy(va_list <i>dest</i>, va_list <i>src</i>)</code></td>
1185<td>Makes a copy of the variadic function arguments</td>
pkasting7f0693b32016-10-31 20:27:501186<td><a href="http://en.cppreference.com/w/cpp/utility/variadic/va_copy">va_copy</a></td>
Nico Weber019d40f2014-09-23 20:21:591187<td></td>
1188</tr>
1189
1190<tr>
1191<td>Weak Pointers</td>
1192<td><code>std::weak_ptr</code></td>
1193<td>Allows a weak reference to a <code>std::shared_ptr</code></td>
pkasting07c0959a2016-04-14 22:16:431194<td><a href="http://en.cppreference.com/w/cpp/memory/weak_ptr">std::weak_ptr</a></td>
1195<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:591196</tr>
1197
1198<tr>
1199<td>Wide String Support</td>
pkasting07c0959a2016-04-14 22:16:431200<td><code>std::wstring_convert</code>, <code>std::wbuffer_convert</code><br />
1201<code>std::codecvt_utf8</code>, <code>std::codecvt_utf16</code>, <code>std::codecvt_utf8_utf16</code></td>
Nico Weber019d40f2014-09-23 20:21:591202<td>Converts between string encodings</td>
pkasting07c0959a2016-04-14 22:16:431203<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>
1204<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:591205</tr>
1206
1207</tbody>
1208</table>
1209
Nico Weber81c1feb2017-07-31 03:25:131210<h3 id="blacklist_stdlib_review"><a name="library-review-14"></a>C++14 Standard Library Features To Be Discussed</h3>
1211
1212<p>The following C++14 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.</p>
1213
1214<table id="banned_stdlib" class="unlined striped">
1215
1216<tbody>
1217<tr>
1218<th style='width:240px;'>Feature</th>
1219<th style='width:240px;'>Snippet</th>
1220<th style='width:240px;'>Description</th>
1221<th style='width:240px;'>Documentation Link</th>
1222<th style='width:240px;'>Notes</th>
1223</tr>
1224
1225<tr>
Jeremy Romanabd27842017-08-04 18:27:551226<td><code>std::complex</code> literals</td>
1227<td><code>using namespace std::complex_literals;<br>std::complex&lt;double&gt; c = 2.0 + 0.5i;</code></td>
Jeremy Roman674334b2017-08-04 19:17:341228<td>Allows <code>std::complex</code> objects to be more easily constructed.</td>
Jeremy Romanabd27842017-08-04 18:27:551229<td><a href="http://en.cppreference.com/w/cpp/numeric/complex/operator%22%22i">std::literals::complex_literals</a></td>
1230<td></td>
1231</tr>
1232
Nico Weber81c1feb2017-07-31 03:25:131233<td><code>std::string</code> literals</td>
1234<td><code>
1235#include &lt;string&gt;<br>
1236using std::literals::string_literals::operator"" s;<br>
1237auto s = "asdf"s; // deduces to std::string</code></td>
1238<td>Allows literals of type <code>std::string</code></td>
1239<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s">std::literals::string_literals::operator""s</a></td>
1240<td></td>
1241</tr>
1242
Nico Weber81c1feb2017-07-31 03:25:131243</tbody>
1244</table>
1245
Nico Weber019d40f2014-09-23 20:21:591246</div>
1247</body>
1248</html>