Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / styleguide / c++ / c++11.html
blobd1b26808d7c27a07fb79ce09dd3a96b7e9eae665
1 <!DOCTYPE html>
2 <!--
3 Copyright 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>C++11 use in Chromium</title>
11 <link rel="stylesheet" href="c++11.css">
12 <style>
13 table tbody tr td:first-child {
14 font-weight: bold;
15 font-size: 110%;
17 </style>
18 </head>
19 <body>
20 <div id="content">
21 <h1>C++11 use in Chromium</h1>
23 <p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium
24 checkout.</i></p>
26 <p>This document summarizes the features of C++11 (both in the language itself
27 and in enhancements to the Standard Library) and describes which features are
28 allowed in Chromium and contains pointers to more detailed information. The
29 Guide applies to Chromium and its subprojects. Subprojects can choose to be
30 more restrictive if they need to compile on more toolchains than Chromium.</p>
32 <p>You can propose to make a feature available or to ban a
33 feature by sending an email to chromium-dev. Ideally include a short blurb
34 on what the feature is, and why you think it should or should not be allowed.
35 Ideally, the list will arrive at some consensus and the wiki page will be
36 updated to mention that consensus. If there's no consensus,
37 <code>src/styleguide/C++/OWNERS</code> get to decide -- for divisive features, we expect
38 the decision to be to not use the feature yet and possibly discuss it again a
39 few months later, when we have more experience with the language.</p>
41 <p class="warning">Unless otherwise noted, <strong>no</strong> C++11
42 <strong>library</strong> features are allowed.</p>
44 <h2 id="whitelist">C++11 Allowed Features</h2>
46 <p>The following features are currently allowed.</p>
48 <table id="whitelist_lang_list" class="unlined striped">
49 <tbody>
51 <tr>
52 <th style='width:220px;'>Feature</th>
53 <th style='width:260px;'>Snippet</th>
54 <th style='width:240px;'>Description</th>
55 <th style='width:240px;'>Documentation Link</th>
56 <th style='width:240px;'>Notes and Discussion Thread</th>
57 </tr>
59 <tr>
60 <td>Aliases</td>
61 <td><code>using <i>new_alias</i> = <i>typename</i></code></td>
62 <td>Allow parameterized typedefs</td>
63 <td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias (using syntax)</a></td>
64 <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>
65 </tr>
67 <tr>
68 <td>Angle Bracket Parsing in Templates</td>
69 <td><code>&gt;&gt;</code> for <code>&gt; &gt;</code> and <br />
70 <code>&lt;::</code> for <code>&lt; ::</code></td>
71 <td>More intuitive parsing of template parameters</td>
72 <td><a href="http://stackoverflow.com/questions/15785496/c-templates-angle-brackets-pitfall-what-is-the-c11-fix">
73 C++ Templates Angle Brackets Pitfall</a></td>
74 <td>Recommended to increase readability. Approved without discussion.</td>
75 </tr>
77 <tr>
78 <td>Automatic Types</td>
79 <td><code>auto</code></td>
80 <td>Automatic type deduction</td>
81 <td>TODO: documentation link</td>
82 <td>Use according to the <a
83 href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#auto">Google
84 Style Guide on <code>auto</code></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>
85 </tr>
87 <tr>
88 <td>Declared Type Accessor</td>
89 <td><code>decltype(<i>expression</i>)</code></td>
90 <td>Provides a means to determine the type of an expression at compile-time,
91 useful most often in templates.</td>
92 <td><a href="http://en.cppreference.com/w/cpp/language/decltype">
93 decltype specifier</a></td>
94 <td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/_zoNvZd_dSo">Discussion thread</a></td>
95 </tr>
97 <tr>
98 <td>Default Function Creation</td>
99 <td><code><i>Function</i>(<i>arguments</i>) = default;</code></td>
100 <td>Instructs the compiler to generate a default version
101 of the indicated function</td>
102 <td><a href="http://stackoverflow.com/questions/823935/whats-the-point-in-defaulting-functions-in-c11">
103 What's the point in defaulting functions in C++11?</a></td>
104 <td>Doesn't work for move constructors and move assignment operators in MSVC2013.
105 <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/qgU4mh_MpGA">Discussion thread</a></td>
106 </tr>
108 <tr>
109 <td>Delegated Constructors</td>
110 <td><code>Class() : Class(0) {}</code><br />
111 <code>Class(<i>type</i> <i>var</i>) : Class(<i>var</i>, 0)</code></td>
112 <td>Allow overloaded constructors to use common initialization code</td>
113 <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">
114 Introduction to the C++11 feature: delegating constructors</a></td>
115 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/0zVA8Ctx3Xo">Discussion thread</a></td>
116 </tr>
118 <tr>
119 <td>Enumerated Type Classes and Enum Bases</td>
120 <td><code>enum class <i>classname</i></code><br>
121 <code>enum class <i>classname</i> : <i>base-type</i></code><br>
122 <code>enum <i>enumname</i> : <i>base-type</i></code></td>
123 <td>Provide enums as full classes, with no implicit
124 conversion to booleans or integers. Provide an explicit underlying type for
125 enum classes and regular enums.</td>
126 <td><a href="http://www.stroustrup.com/C++11FAQ.html#enum">enum-class</a></td>
127 <td>Enum classes are still enums and follow enum naming rules
128 (which means SHOUTY_CASE in the <a href="http://www.chromium.org/developers/coding-style#Naming">current style guide</a>).
129 <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Q5WmkAImanc">Discussion thread</a></td>
130 </tr>
132 <tr>
133 <td>Final Specifier</td>
134 <td><code>final</code></td>
135 <td> Indicates that a class or function is final and cannot be overridden</td>
136 <td><a href="http://en.cppreference.com/w/cpp/language/final">final Language Reference</a></td>
137 <td>Recommended for new code. Existing uses of the <code>FINAL</code> macro will be <a href="https://crbug.com/417463">replaced throughout the codebase</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
138 </tr>
140 <tr>
141 <td>Function Suppression</td>
142 <td><code><i>Function</i>(<i>arguments</i>) = delete;</code></td>
143 <td>Suppresses the implementation of a function, especially a
144 synthetic function such as a copy constructor</td>
145 <td>TODO: documentation link</td>
146 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/i1o7-RNRnMs">Discussion thread</a></td>
147 </tr>
149 <tr>
150 <td>Lambda Expressions</td>
151 <td><code>[<i>captures</i>](<i>params</i>) -&gt; <i>ret</i> { <i>body</i> }</code></td>
152 <td>Anonymous functions</td>
153 <td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
154 <td>Do not bind or store lambdas; use <code>base::Bind</code> and
155 <code>base::Callback</code> instead, because they offer protection against a
156 large class of object lifetime mistakes. Don't use default captures
157 (<code>[=]</code>, <code>[&amp;]</code> &ndash; <a
158 href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Lambda_expressions">Google Style Guide</a>).
159 Lambdas are typically useful as a parameter to methods or
160 functions that will use them immediately, such as those in
161 <code>&lt;algorithm&gt;</code>. <a
162 href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnciQ">Discussion
163 thread</a></td>
164 </tr>
166 <tr>
167 <td>Local Types as Template Arguments</td>
168 <td></td>
169 <td>Allows local and unnamed types as template arguments</td>
170 <td><a href="http://stackoverflow.com/questions/742607/using-local-classes-with-stl-algorithms">
171 Local types, types without linkage and unnamed types as template arguments</a></td>
172 <td>Usage should be rare. Approved without discussion.</td>
173 </tr>
175 <tr>
176 <td>Non-Static Class Member Initializers</td>
177 <td>
178 <code>
179 class C {<br />
180 <i>type</i> <i>var</i> = <i>value</i>;<br/>
181 C() // copy-initializes <i>var</i><br/>
182 </code>
183 <td>Allows non-static class members to be initialized at their definitions (outside constructors)</td>
184 <td><a href="http://en.cppreference.com/w/cpp/language/data_members">
185 Non-static data members</a></td>
186 <td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Initialization">Google
187 Style Guide</a>.
188 <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zqB-DySA4V0">Discussion thread</a>
189 </td>
190 </tr>
192 <tr>
193 <td>Null Pointer Constant</td>
194 <td><code>nullptr</code></td>
195 <td>Declares a type-safe null pointer</td>
196 <td>TODO: documentation link</td>
197 <td>Recommended for new code.
198 <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/4mijeJHzxLg">Discussion thread</a>.
199 <a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#0_and_nullptr/NULL">Google Style Guide</a>.
200 Note: <code>std::nullptr_t</code> is a library feature and not available.
201 </td>
202 </tr>
204 <tr>
205 <td>Override Specifier</td>
206 <td><code>override</code></td>
207 <td>Indicates that a class or function overrides a base implementation</td>
208 <td><a href="http://en.cppreference.com/w/cpp/language/override">override Language Reference</a></td>
209 <td>Recommended for new code. Existing uses of the <code>OVERRIDE</code> macro will be <a href="https://crbug.com/417463">replaced throughout the codebase</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion</a></td>
210 </tr>
212 <tr>
213 <td>Range-Based For Loops</td>
214 <td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td>
215 <td>Facilitates a more concise syntax for iterating over the elements
216 of a container (or a range of iterators) in a <code>for</code> loop</td>
217 <td>TODO: documentation link</td>
218 <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>
219 </tr>
221 <tr>
222 <td>Standard Integers</td>
223 <td>Typedefs within <code>&lt;stdint.h&gt;</code>
224 and <code>&lt;inttypes&gt;</code></td>
225 <td>Provides fixed-size integers independent of platforms</td>
226 <td><a href="http://www.cplusplus.com/reference/cstdint/">
227 &lt;stdint.h&gt; (cstdint)</a></td>
228 <td>Already in common use in the codebase. Approved without discussion.</td>
229 </tr>
231 <tr>
232 <td>Static Assertions</td>
233 <td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td>
234 <td>Tests compile-time conditions</td>
235 <td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Assertion</a></td>
236 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/POISBQEhGzU">Discussion thread</a></td>
237 </tr>
239 <tr>
240 <td>Variadic Macros</td>
241 <td><code>#define <i>MACRO</i>(...) <i>Impl</i>(<i>args</i>, __VA_ARGS__)</code></td>
242 <td>Allows macros that accept a variable number of arguments</td>
243 <td><a href="http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard">
244 Are Variadic macros nonstandard?</a></td>
245 <td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/sRx9j3CQqyA">Discussion thread</a></td>
246 </tr>
248 <tr>
249 <td>Variadic Templates</td>
250 <td><code>template &lt;<i>typename</i> ... <i>arg</i>&gt;</code></td>
251 <td>Allows templates that accept a variable number of arguments</td>
252 <td>TODO: documentation link</td>
253 <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>
254 </tr>
256 </tbody>
257 </table>
259 <h2 id="blacklist">C++11 Blacklist (Disallowed and Banned Features)</h2>
261 <p>This section lists features that are not allowed to be used yet.
263 <h3 id="blacklist_banned">C++11 Banned Features</h3>
265 <p>This section lists C++11 features that are not allowed in the Chromium
266 codebase.
267 </p>
269 <table id="banned_list" class="unlined striped">
270 <tbody>
272 <tr>
273 <th style='width:240px;'>Feature or Library</th>
274 <th style='width:240px;'>Snippet</th>
275 <th style='width:240px;'>Description</th>
276 <th style='width:240px;'>Documentation Link</th>
277 <th style='width:240px;'>Notes</th>
278 </tr>
280 <tr>
281 <td>Constant Expressions</td>
282 <td><code>constexpr</code></td>
283 <td>Compile-time constant expressions</td>
284 <td>TODO: documentation link</td>
285 <td>Doesn't work in MSVS2013. Reevalute once it does. <a
286 href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Use_of_constexpr">Google
287 Style Guide on <code>constexpr</code></a></td>
288 </tr>
290 <tr>
291 <td>Explicit Conversion Operators</td>
292 <td><code>explicit operator <i>type</i>() {
293 <br />&nbsp;&nbsp;// code<br /> }</code></td>
294 <td>Allows conversion operators that cannot be implicitly invoked</td>
295 <td><a href="http://en.cppreference.com/w/cpp/language/explicit">
296 explicit specifier</a></td>
297 <td><a href="https://connect.microsoft.com/VisualStudio/feedback/details/811334/bug-in-vs-2013-support-for-explicit-conversion-operators">Doesn't work in MSVS2013</a>. Reevaluate once it does. <a href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/zGF1SrQ-1HQ/BAiC12vwPeEJ">Discussion thread</a></td>
298 </tr>
300 <tr>
301 <td>Function Local Variable</td>
302 <td><code>__func__</code></td>
303 <td>Provides a local variable of the name of the enclosing
304 function for logging purposes</td>
305 <td><a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=338">
306 The __func__ Predeclared Identifier is Coming to C++</a></td>
307 <td>Doesn't work in MSVS2013. Reevaluate once it does. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ojGfcgSDzHM">Discussion thread</a></td>
308 </tr>
310 <tr>
311 <td>Inherited Constructors</td>
312 <td><code>class Derived : Base {
313 <br />&nbsp;&nbsp;using Base::Base;
314 <br />};</code></td>
315 <td>Allow derived classes to inherit constructors from base classes</td>
316 <td><a href="http://en.cppreference.com/w/cpp/language/using_declaration">Using-declaration</a></td>
317 <td>Doesn't work in MSVS2013. Reevaluate once it does. <a
318 href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/BULzgIKZ-Ao/PLO7_GoVNvYJ">Discussion thread</a></td>
319 </tr>
321 <tr>
322 <td><code>long long</code> Type</td>
323 <td><code>long long <i>var</i>= <i>value</i>;</code></td>
324 <td>An integer of at least 64 bits</td>
325 <td><a href="http://en.cppreference.com/w/cpp/language/types">
326 Fundamental types</a></td>
327 <td>Use an 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>
328 </tr>
330 <tr>
331 <td>Raw String Literals</td>
332 <td><code>string <i>var</i>=R&quot;(<i>raw_string</i>)&quot;;</code></td>
333 <td>Allows a string to be encoded without any escape
334 sequences, easing parsing in regex expressions, for example</td>
335 <td>TODO: documentation link</td>
336 <td>Causes incorrect line numbers in MSVS2014 and gcc. Reevaluate once that works. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
337 </tr>
339 <tr>
340 <td>Rvalue References (and Move Semantics)</td>
341 <td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</code></td>
342 <td>Reference that only binds to a temporary object</td>
343 <td>TODO: documentation link</td>
344 <td>To be revisited in the future. Allowed in exceptional cases where approved by the OWNERS of src/styleguide/c++/.</td>
345 </tr>
347 <tr>
348 <td>(Uniform) Initialization Syntax</td>
349 <td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></td>
350 <td>Allows any object of primitive, aggregate or class
351 type to be initialized using brace syntax</td>
352 <td>TODO: documentation link</td>
353 <td>Dangerous without library support, see thread. Reevaulate once we have C++11 library support. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GF96FshwHLw">Discussion thread</a></td>
354 </tr>
356 <tr>
357 <td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td>
358 <td><code>char16_t</code> and <code>char32_t</code></td>
359 <td>Provides character types for handling 16-bit
360 and 32-bit code units (useful for encoding
361 UTF-16 and UTF-32 string data)</td>
362 <td><a href="http://en.cppreference.com/w/cpp/language/types">
363 Fundamental types</a></td>
364 <td>Doesn't work in MSVS2013. Reevaluate once it does. Non-UTF-8 text is
365 banned by the
366 <a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Non-ASCII_Characters">
367 C++ Style Guide</a>. However, may be useful for
368 consuming non-ASCII data. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ME2kL7_Kvyk">Discussion thread</a></td>
369 </tr>
371 <tr>
372 <td>UTF-8, UTF-16, UTF-32 String Literals</td>
373 <td><code>u8&quot;<i>string</i>&quot;, u&quot;<i>string</i>&quot;, U&quot;<i>string</i>&quot;</code></td>
374 <td>Enforces UTF-8, UTF-16, UTF-32 encoding on all string literals</td>
375 <td><a href="http://en.cppreference.com/w/cpp/language/string_literal">
376 string literal</a></td>
377 <td>Does not yet work in MSVS2013. Reevaluate once it does. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/gcoUbcjfsII">Discussion thread</a></td>
378 </tr>
380 </tbody>
381 </table>
383 <h3 id="blacklist_review">C++11 Features To Be Discussed</h3>
385 <p>The following C++ language features are currently disallowed.
386 See the top of this page on how to propose moving a feature from this list
387 into the allowed or banned sections. Note that not all of these features
388 work in all our compilers yet.</p>
390 <table id="blacklist_review_list" class="unlined striped">
391 <tbody>
393 <tr>
394 <th style='width:240px;'>Feature</th>
395 <th style='width:240px;'>Snippet</th>
396 <th style='width:240px;'>Description</th>
397 <th style='width:240px;'>Documentation Link</th>
398 <th style='width:240px;'>Notes</th>
399 </tr>
401 <tr>
402 <td>Alignment Features</td>
403 <td>
404 <code>alignas</code> specifier,
405 <code>std::alignment_of&lt;T&gt;</code>,
406 <code>std::aligned_union&lt;Size, ...Types&gt;</code> and
407 <code>std::max_align_t</code></td>
408 <td>Object alignment</td>
409 <td><a href="http://en.cppreference.com/w/cpp/types/alignment_of">std::alignment_of</a></td>
410 <td></td>
411 </tr>
413 <tr>
414 <td>Attributes</td>
415 <td><code>[[<i>attribute_name</i>]]</code></td>
416 <td>Attaches properties to declarations that
417 specific compiler implementations may use.</td>
418 <td><a href="http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/">
419 C++11 generalized attributes</a></td>
420 <td></td>
421 </tr>
423 <tr>
424 <td>Default Function Template Arguments</td>
425 <td><code>template &lt;typename T = <i>type</i>&gt; <br />
426 &nbsp;&nbsp;<i>type</i> <i>Function</i>(T <i>var</i>) {}</code></td>
427 <td>Allow function templates, like classes, to have default arguments</td>
428 <td><a href="http://stackoverflow.com/questions/2447458/default-template-arguments-for-function-templates">
429 Default Template Arguments for Function Templates</a></td>
430 <td></td>
431 </tr>
433 <tr>
434 <td>Exception Features</td>
435 <td><code>noexcept</code>, <code>exception_ptr</code>,
436 <code>current_exception()</code>, <code>rethrow_exception</code>,
437 and <code>nested_exception</code></td>
438 <td>Enhancements to exception throwing and handling</td>
439 <td><a href="http://en.cppreference.com/w/cpp/error/exception">
440 std::exception</a></td>
441 <td>Exceptions are banned by the
442 <a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Exceptions"> C++ Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
443 </tr>
445 <tr>
446 <td>Inline Namespaces</td>
447 <td><code>inline</code></td>
448 <td>Allows better versioning of namespaces</td>
449 <td><a href="http://en.cppreference.com/w/cpp/language/namespace">Namespaces</a></td>
450 <td>Unclear how it will work with components</td>
451 </tr>
453 <tr>
454 <td>Union Class Members</td>
455 <td><code>union <i>name</i> { <i>class</i> <i>var</i>}</code></td>
456 <td>Allows class type members</td>
457 <td><a href="http://en.cppreference.com/w/cpp/language/union">
458 Union declarations</a></td>
459 <td></td>
460 </tr>
462 <tr>
463 <td>User-Defined Literals</td>
464 <td><code><i>type</i> <i>var</i> = <i>literal_value</i>_<i>type</i></code></td>
465 <td>Allows user-defined literal expressions</td>
466 <td>TODO: documentation link</td>
467 <td></td>
468 </tr>
470 </tbody>
471 </table>
473 <h3 id="blacklist_stdlib">C++11 Standard Library features</h3>
475 <details>
477 <p><summary class="note">All C++11 <strong>Standard Library features are currently
478 banned</strong>, because they are not supported on all of our toolchains yet.
479 In particular, chromium/android is currently using STLport, and chromium/mac is
480 currently using libstdc++4.2, which predate C++11.
481 </summary></p>
483 <table id="banned_stdlib" class="unlined striped">
485 <tbody>
486 <tr>
487 <th style='width:240px;'>Feature</th>
488 <th style='width:240px;'>Snippet</th>
489 <th style='width:240px;'>Description</th>
490 <th style='width:240px;'>Documentation Link</th>
491 <th style='width:240px;'>Style Guide Usage</th>
492 </tr>
494 <tr>
495 <td>Address Retrieval</td>
496 <td><code>std::addressof()</code></td>
497 <td>Obtains the address of an object even with overloaded <code>operator&amp;</code></td>
498 <td><a href="http://en.cppreference.com/w/cpp/memory/addressof">std::addressof</a></td>
499 <td>Usage should be rare as
500 <a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Operator_Overloading">
501 Operator Overloading</a> is rare and <code>&amps;</code>
502 should suffice in most cases. May be preferable
503 over <code>&amps;</code> for performing object
504 identity checks.</td>
505 </tr>
507 <tr>
508 <td>Aligned Storage</td>
509 <td><code>std::aligned_storage&lt;Size, Align&gt;::type</code></td>
510 <td>Declare uninitialized storage having a specified alignment.</td>
511 <td><a href="http://en.cppreference.com/w/cpp/types/aligned_storage">std::aligned_storage</a></td>
512 <td>Note: <code>std::aligned_storage</code> is allowed, but some other C++11
513 alignment features are still disallowed.</td>
514 </tr>
516 <tr>
517 <td>Allocator Traits</td>
518 <td><code>std::allocator_traits</code></td>
519 <td>Provides an interface for accessing custom allocators</td>
520 <td><a href="http://en.cppreference.com/w/cpp/memory/allocator_traits">
521 std::allocator_traits</a></td>
522 <td>Usage should be rare.</td>
523 </tr>
525 <tr>
526 <td>Atomics</td>
527 <td><code>std::atomic</code> and others in <code>&lt;atomic&gt;</code></td>
528 <td>Fine-grained atomic types and operations</td>
529 <td><a href="http://en.cppreference.com/w/cpp/atomic">&lt;atomic&gt;</a></td>
530 <td></td>
531 </tr>
533 <tr>
534 <td>Arrays</td>
535 <td><code>std::array</code></td>
536 <td>A fixed-size replacement for built-in arrays, with STL support</td>
537 <td><a href="http://en.cppreference.com/w/cpp/container/array">
538 std::array</a></td>
539 <td></td>
540 </tr>
542 <tr>
543 <td>Begin and End Non-Member Functions</td>
544 <td><code>std::begin()</code> and <code>std::end()</code></td>
545 <td>Allows use of free functions on any container, including
546 built-in arrays</td>
547 <td><a href="http://en.cppreference.com/w/cpp/iterator/begin">
548 std::begin</a> and
549 <a href="http://en.cppreference.com/w/cpp/iterator/end">
550 std::end</a></td>
551 <td>Useful for built-in arrays.</td>
552 </tr>
554 <tr>
555 <td>Bind Operations</td>
556 <td><code>std::bind(<i>function</i>, <i>args</i>, ...)</code></td>
557 <td>Declares a function object bound to certain arguments</td>
558 <td>TODO: documentation link</td>
559 <td></td>
560 </tr>
562 <tr>
563 <td>C Floating-Point Environment</td>
564 <td><code>&lt;cfenv&gt;</code></td>
565 <td>Provides floating point status flags and control modes for C-compatible code</td>
566 <td><a href="http://en.cppreference.com/w/cpp/header/cfenv">Standard library header &lt;cfenv&gt;</a></td>
567 <td>Compilers do not support use</td>
568 </tr>
570 <tr>
571 <td>Chrono Library</td>
572 <td><code>&lt;chrono&gt;</code></td>
573 <td>Provides a standard date and time library</td>
574 <td><a href="http://en.cppreference.com/w/cpp/chrono">Date and time utilities</a></td>
575 <td></td>
576 </tr>
578 <tr>
579 <td>Complex Inverse Trigonometric and Hyperbolic Functions</td>
580 <td>Functions within <code>&lt;complex&gt;</code></td>
581 <td>Adds inverse trigonomentric and hyperbolic non-member functions to
582 the <code>&lt;complex&gt;</code> library.</td>
583 <td><a href="http://en.cppreference.com/w/cpp/numeric/complex">std::complex</a></td>
584 <td></td>
585 </tr>
587 <tr>
588 <td>Conditional Type Selection</td>
589 <td><code>std::enable_if</code> and <code>std::conditional</code></td>
590 <td>Enables compile-time conditional type selection</td>
591 <td><a href="http://en.cppreference.com/w/cpp/types/enable_if">
592 std::enable_if</a> and
593 <a href="http://en.cppreference.com/w/cpp/types/conditional">
594 conditional</a></td>
595 <td></td>
596 </tr>
598 <tr>
599 <td>Constant Iterator Methods on Containers</td>
600 <td><code>std::cbegin()</code> and <code>std::cend()</code></td>
601 <td>Enforces iteration methods that don't change container contents</td>
602 <td>TODO: documentation link</td>
603 <td></td>
604 </tr>
606 <tr>
607 <td>Construct Elements in Containers</td>
608 <td><code>emplace()</code>,<code>emplace_back()</code>,
609 <code>emplace_front()</code>, <code>emplace_hint()</code></td>
610 <td>Constructs elements directly within a container without a copy
611 or a move</td>
612 <td>TODO: documentation link</td>
613 <td>Use where element construction within a container
614 is needed.</td>
615 </tr>
617 <tr>
618 <td>Container Compaction Functions</td>
619 <td><code>std::vector::shrink_to_fit()</code>,
620 <code>std::deque::shrink_to_fit()</code>, and
621 <code>std::string::shrink_to_fit()</code></td>
622 <td>Requests the removal of unused space
623 in the container</td>
624 <td><a href="http://en.cppreference.com/w/cpp/container/vector/shrink_to_fit">
625 std::vector::shrink_to_fit</a>,
626 <a href="http://en.cppreference.com/w/cpp/container/deque/shrink_to_fit">
627 std::deque::shrink_to_fit</a>, and
628 <a href="http://en.cppreference.com/w/cpp/string/basic_string/shrink_to_fit">
629 std::basic_string::shrink_to_fit</a></td>
630 <td></td>
631 </tr>
633 <tr>
634 <td>Date/Time String Formatting Specifiers</td>
635 <td><code>std::strftime()</code></td>
636 <td>Converts date and time information into a
637 formatted string using new specifiers</td>
638 <td><a href="http://en.cppreference.com/w/cpp/chrono/c/strftime">
639 std::strftime</a></td>
640 <td></td>
641 </tr>
643 <tr>
644 <td>Function Return Type Deduction</td>
645 <td><code>std::result_of&lt;<i>Functor(ArgTypes...)</i>&gt;</code></td>
646 <td>Extracts the return type from the type signature of
647 a function call invocation at compile-time.</td>
648 <td><a href="http://en.cppreference.com/w/cpp/types/result_of">
649 std::result_of</a></td>
650 <td>
651 <a href="http://stackoverflow.com/questions/15486951/why-does-stdresult-of-take-an-unrelated-function-type-as-a-type-argument">
652 Why does std::result_of take an (unrelated) function type as a type argument?
653 </a></td>
654 </tr>
656 <tr>
657 <td>Function Objects</td>
658 <td><code>std::function</code></td>
659 <td>Wraps a standard polymorphic function</td>
660 <td>TODO: documentation link</td>
661 <td></td>
662 </tr>
664 <tr>
665 <td>Forward Lists</td>
666 <td><code>std::forward_list</code></td>
667 <td>Provides an efficient singly linked list</td>
668 <td><a href="http://en.cppreference.com/w/cpp/container/forward_list">
669 std::forward_list</a></td>
670 <td></td>
671 </tr>
673 <tr>
674 <td>Gamma Natural Log</td>
675 <td><code>std::lgamma()</code></td>
676 <td>Computes the natural log of the gamma of a
677 floating point value</td>
678 <td><a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma">
679 std::lgamma</a></td>
680 <td></td>
681 </tr>
683 <tr>
684 <td>Garbage Collection Features</td>
685 <td><code>std::{un}declare_reachable()</code> and
686 <code>std::{un}declare_no_pointers()</code></td>
687 <td>Enables garbage collection implementations</td>
688 <td><a href="http://en.cppreference.com/w/cpp/memory/gc/declare_reachable">
689 std::declare_reachable</a>
690 and <a href="http://en.cppreference.com/w/cpp/memory/gc/declare_no_pointers">
691 std::declare_no_pointers</a></td>
692 <td></td>
693 </tr>
695 <tr>
696 <td>Heap Validation</td>
697 <td><code>std::is_heap()</code></td>
698 <td>Checks whether an iterator range is in fact a heap</td>
699 <td>TODO: documentation link</td>
700 <td></td>
701 </tr>
703 <tr>
704 <td>Is Nan</td>
705 <td><code>std::isnan()</code></td>
706 <td>Determines if a floating point value is not-a-number</td>
707 <td><a href="http://en.cppreference.com/w/cpp/numeric/math/isnan">std::isnan</a></td>
708 <td></td>
709 </tr>
711 <tr>
712 <td>Iterator Operators</td>
713 <td><code>std::next()</code> and <code>std::prev()</code></td>
714 <td>Copies an iterator and increments or decrements the copy by
715 some value</td>
716 <td><a href="http://en.cppreference.com/w/cpp/iterator/next">std::next</a>
717 and <a href="http://en.cppreference.com/w/cpp/iterator/prev">std::prev</a>
718 </td>
719 <td></td>
720 </tr>
722 <tr>
723 <td>Initializer Lists</td>
724 <td><code>std::initializer_list&lt;T&gt;</code></td>
725 <td>Allows containers to be initialized with aggregate elements</td>
726 <td>TODO: documentation link</td>
727 <td></td>
728 </tr>
730 <tr>
731 <td>Move Semantics</td>
732 <td><code>std::move()</code></td>
733 <td>Facilitates efficient move operations</td>
734 <td><a href="http://en.cppreference.com/w/cpp/utility/move">
735 <code>std::move</code> reference</a></td>
736 <td></td>
737 </tr>
739 <tr>
740 <td>Pointer Traits Class Template</td>
741 <td><code>std::pointer_traits</code></td>
742 <td>Provides a standard way to access properties
743 of pointers and pointer-like types</td>
744 <td><a href="http://en.cppreference.com/w/cpp/memory/pointer_traits">
745 std::pointer_traits</a></td>
746 <td>Useful for determining the element type
747 pointed at by a (possibly smart) pointer.</td>
748 </tr>
750 <tr>
751 <td>Random Number Generators</td>
752 <td>Functions within <code>&lt;random&gt;</code></td>
753 <td>Random number generation algorithms and utilities</td>
754 <td><a href="http://en.cppreference.com/w/cpp/numeric/random">
755 Pseudo-random number generation</a></td>
756 <td></td>
757 </tr>
759 <tr>
760 <td>Ratio Template Class</td>
761 <td><code>std::ratio&lt;<i>numerator</i>, <i>denominator</i>&gt;</code></td>
762 <td>Provides compile-time rational numbers</td>
763 <td>TODO: documentation link</td>
764 <td></td>
765 </tr>
767 <tr>
768 <td>Reference Wrapper Classes</td>
769 <td><code>std::reference_wrapper</code> and
770 <code>std::ref()</code>, <code>std::cref()</code></td>
771 <td>Allows you to wrap a reference within a standard
772 object (and use those within containers)</td>
773 <td><a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=217">
774 Reference Wrappers</a></td>
775 <td></td>
776 </tr>
778 <tr>
779 <td>Regex Library</td>
780 <td><code>&lt;regex&gt;</code></td>
781 <td>Provides a standard regular expressions library</td>
782 <td><a href="http://en.cppreference.com/w/cpp/regex">Regular expressions library</a></td>
783 <td></td>
784 </tr>
786 <tr>
787 <td>Shared Pointers</td>
788 <td><code>std::shared_ptr</code></td>
789 <td>Allows shared ownership of a pointer through reference counts</td>
790 <td><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr">std::shared_ptr</a></td>
791 <td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers">
792 Ownership and Smart Pointers</a></td>
793 </tr>
795 <tr>
796 <td>Soft Program Exits</td>
797 <td><code>std::at_quick_exit()</code>
798 and <code>std::quick_exit()</code></td>
799 <td>Allows registration of functions to be called upon exit,
800 allowing cleaner program exit than <code>abort()</code> or
801 <code>exit</code></td>
802 <td><a href="http://en.cppreference.com/w/cpp/utility/program/quick_exit">
803 std:quick_exit</a></td>
804 <td></td>
805 </tr>
807 <tr>
808 <td>String Direct Reference Functions</td>
809 <td><code>std::string::front()</code> and <code>std::string::back()</code></td>
810 <td>Returns a reference to the front or back of a string</td>
811 <td><a href="http://en.cppreference.com/w/cpp/string/basic_string/front">
812 std::basic_string::front</a> and
813 <a href="http://en.cppreference.com/w/cpp/string/basic_string/back">
814 std::basic_string::back</a></td>
815 <td></td>
816 </tr>
818 <tr>
819 <td>String to Number Functions</td>
820 <td><code>std::stoi()</code>, <code>std::stol()</code>,
821 <code>std::stoul()</code>, <code>std::stoll</code>, <code>std::stoull()</code>,
822 <code>std::stof()</code>, <code>std::stod()</code>, <code>std::stold()</code>,
823 and <code>std::to_string()</code></td>
824 <td>Converts strings to numbers</td>
825 <td><a href="http://en.cppreference.com/w/cpp/string/basic_string/stol">
826 std::stoi, std::stol, std::stoll</a>,
827 <a href="http://en.cppreference.com/w/cpp/string/basic_string/stoul">
828 std::stoul, std::stoull</a>, and
829 <a href="http://en.cppreference.com/w/cpp/string/basic_string/stof">
830 std::stof, std::stod, std::stold</a> </td>
831 <td></td>
832 </tr>
834 <tr>
835 <td>STL Algorithms</td>
836 <td>Functions within <code>&lt;algorithm&gt;</code>.</td>
837 <td>Enhancements to the set of STL algorithms</td>
838 <td>See the <a href="http://en.cppreference.com/w/cpp/algorithm">
839 Algorithms library</a> for a complete list.</td>
840 <td></td>
841 </tr>
843 <tr>
844 <td>System Errors</td>
845 <td><code>&lt;system_error&gt;</code></td>
846 <td>Provides a standard system error library</td>
847 <td><a href="http://en.cppreference.com/w/cpp/error/system_error">std::system_error</a></td>
848 <td></td>
849 </tr>
851 <tr>
852 <td>Trailing Return Types</td>
853 <td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td>
854 <td>Allows trailing function return value syntax</td>
855 <td><a href="http://en.cppreference.com/w/cpp/language/function">
856 Declaring functions</a></td>
857 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion thread</a></td>
858 </tr>
860 <tr>
861 <td>Thread Library</td>
862 <td><code>&lt;thread&gt; support, including &lt;future&gt;,
863 &lt;mutex&gt;, &lt;condition_variable&gt;</code></td>
864 <td>Provides a standard mulitthreading library using <code>std::thread</code> and associates</td>
865 <td><a href="http://en.cppreference.com/w/cpp/thread">Thread support library</a></td>
866 <td></td>
867 </tr>
869 <tr>
870 <td>Tuples</td>
871 <td><code>std::tuple</code></td>
872 <td>A fixed-size ordered collection of values of mixed types</td>
873 <td>TODO: documentation link</td>
874 <td></td>
875 </tr>
877 <tr>
878 <td>Type-Generic Math Functions</td>
879 <td>Functions within <code>&lt;ctgmath&gt;</code></td>
880 <td>Provides a means to call real or complex functions
881 based on the type of arguments</td>
882 <td><a href="http://en.cppreference.com/w/cpp/header/ctgmath">
883 Standard library header &lt;ctgmath&gt;</a></td>
884 <td></td>
885 </tr>
887 <tr>
888 <td>Type Info Enhancements</td>
889 <td><code>std::type_index</code> and <code>std::type_info::hash_code()</code></td>
890 <td>Allows type information (most often within containers)
891 that can be copied, assigned, or hashed</td>
892 <td><a href="http://en.cppreference.com/w/cpp/types/type_index">
893 std::type_index</a> and
894 <a href="http://en.cppreference.com/w/cpp/types/type_info/hash_code">
895 std::type_info::hash_code</a></td>
896 <td><code>std::type_index</code> is a thin wrapper for
897 <code>std::type_info</code>, allowing you to use it directly
898 within both associative and unordered containers</td>
899 </tr>
901 <tr>
902 <td>Type Traits</td>
903 <td>Class templates within <code>&lt;type_traits&gt;</code></td>
904 <td>Allows compile-time inspection of the properties of types</td>
905 <td><a href="http://en.cppreference.com/w/cpp/header/type_traits">
906 Standard library header &lt;type_traits&gt;</a></td>
907 <td></td>
908 </tr>
910 <tr>
911 <td>Unique Pointers</td>
912 <td><code>std::unique_ptr&lt;<i>type</i>&gt;</code></td>
913 <td>Defines a pointer with clear and unambiguous ownership</td>
914 <td>TODO: documentation link</td>
915 <td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers">
916 Ownership and Smart Pointers</a></td>
917 </tr>
919 <tr>
920 <td>Unordered Associative Containers</td>
921 <td><code>std::unordered_set</code>, <code>std::unordered_map</code>,
922 <code>std::unordered_multiset</code>, and <code>std::unordered_multimap</code></td>
923 <td>Allows efficient containers of key/value pairs</td>
924 <td><a href="http://en.cppreference.com/w/cpp/container/unordered_map">std::unordered_map</a>
925 and <a href="http://en.cppreference.com/w/cpp/container/unordered_set">std::unordered_set</a>
926 </td>
927 <td></td>
928 </tr>
930 <tr>
931 <td>Variadic Copy Macro</td>
932 <td><code>va_copy(va_list <i>dest</i>, va_list <i>src</i>)</code></td>
933 <td>Makes a copy of the variadic function arguments</td>
934 <td></td>
935 <td></td>
936 </tr>
938 <tr>
939 <td>Weak Pointers</td>
940 <td><code>std::weak_ptr</code></td>
941 <td>Allows a weak reference to a <code>std::shared_ptr</code></td>
942 <td><a href="http://en.cppreference.com/w/cpp/memory/weak_ptr">
943 std::weak_ptr</a></td>
944 <td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers">
945 Ownership and Smart Pointers</a></td>
946 </tr>
948 <tr>
949 <td>Wide String Support</td>
950 <td><code>std::wstring_convert</code>,
951 <code>std::wbuffer_convert</code>.
952 <code>std::codecvt_utf8</code>, <code>std::codecvt_utf16</code>,
953 and <code>std::codecvt_utf8_utf16</code></td>
954 <td>Converts between string encodings</td>
955 <td><a href="http://en.cppreference.com/w/cpp/locale/wstring_convert">
956 std::wstring_convert</a>,
957 <a href="http://en.cppreference.com/w/cpp/locale/wbuffer_convert">
958 std::wbuffer_convert</a>,
959 <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8">
960 std::codecvt_utf8</a>,
961 <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf16">
962 std::codecvt_utf16</a>, and
963 <a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16">
964 std::codecvt_utf8_utf16</a>
965 </td>
966 <td>Non-UTF-8 text is banned by the
967 <a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Non-ASCII_Characters">
968 C++ Style Guide</a>. However, may be useful for
969 consuming non-ASCII data.</td>
970 </tr>
972 </tbody>
973 </table>
975 </details>
977 </div>
978 </body>
979 </html>