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