OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 <html> | 7 <html> |
8 <head> | 8 <head> |
9 <meta charset="utf-8"> | 9 <meta charset="utf-8"> |
10 <title>C++11 use in Chromium</title> | 10 <title>C++11 use in Chromium</title> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 <td>Anonymous functions</td> | 193 <td>Anonymous functions</td> |
194 <td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions<
/a></td> | 194 <td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions<
/a></td> |
195 <td>Lambdas are typically useful as a parameter to methods or functions that wil
l use them immediately, such as those in <code><algorithm></code>. Be care
ful with default captures (<code>[=]</code>, <code>[&]</code>), and do not b
ind 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 pr
event 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.githu
b.io/styleguide/cppguide.html#Lambda_expressions">Google Style Guide</a>. <a hre
f="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnc
iQ">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/for
um/#!topic/cxx/QxjsPELDYdQ">Another discussion thread</a> (about captureless lam
bdas and <code>base::Bind</code>).</td> | 195 <td>Lambdas are typically useful as a parameter to methods or functions that wil
l use them immediately, such as those in <code><algorithm></code>. Be care
ful with default captures (<code>[=]</code>, <code>[&]</code>), and do not b
ind 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 pr
event 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.githu
b.io/styleguide/cppguide.html#Lambda_expressions">Google Style Guide</a>. <a hre
f="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnc
iQ">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/for
um/#!topic/cxx/QxjsPELDYdQ">Another discussion thread</a> (about captureless lam
bdas and <code>base::Bind</code>).</td> |
196 </tr> | 196 </tr> |
197 | 197 |
198 <tr> | 198 <tr> |
199 <td>Local Types as Template Arguments</td> | 199 <td>Local Types as Template Arguments</td> |
200 <td><code>void func() {<br /> | 200 <td><code>void func() {<br /> |
201 class Pred {<br /> | 201 class Pred {<br /> |
202 public:<br /> | 202 public:<br /> |
203 bool operator()(const T&) { ... }<br /> | 203 bool operator()(const T&) { ... }<br /> |
204 };<br /> | 204 };<br /> |
205 std::remove_if(vec.begin(), vec.end(), Pred());</code></td> | 205 std::remove_if(vec.begin(), vec.end(), Pred());</code></td> |
206 <td>Allows local and unnamed types as template arguments</td> | 206 <td>Allows local and unnamed types as template arguments</td> |
207 <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> | 207 <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> |
208 <td>Usage should be rare. Approved without discussion.</td> | 208 <td>Usage should be rare. Approved without discussion.</td> |
209 </tr> | 209 </tr> |
210 | 210 |
211 <tr> | 211 <tr> |
212 <td>Noexcept Specifier</td> | 212 <td>Noexcept Specifier</td> |
213 <td><code>void f() noexcept</code></td> | 213 <td><code>void f() noexcept</code></td> |
214 <td>Specifies that a function will not throw exceptions</td> | 214 <td>Specifies that a function will not throw exceptions</td> |
215 <td><a href="http://en.cppreference.com/w/cpp/language/noexcept_spec">noexcept s
pecifier</a></td> | 215 <td><a href="http://en.cppreference.com/w/cpp/language/noexcept_spec">noexcept s
pecifier</a></td> |
216 <td>Chromium compiles without exception support, but there are still cases where
explicitly marking a function as <code>noexcept</code> may be necessary to comp
ile, or for performance reasons. Usage should be rare. <a href="https://groups.g
oogle.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thre
ad</a></td> | 216 <td>Chromium compiles without exception support, but there are still cases where
explicitly marking a function as <code>noexcept</code> may be necessary to comp
ile, or for performance reasons. Use noexcept for move constructors whenever pos
sible (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> |
217 </tr> | 217 </tr> |
218 | 218 |
219 <tr> | 219 <tr> |
220 <td>Non-Static Class Member Initializers</td> | 220 <td>Non-Static Class Member Initializers</td> |
221 <td><code>class C {<br /> | 221 <td><code>class C {<br /> |
222 <i>type</i> <i>var</i> = <i>value</i>;<br /> | 222 <i>type</i> <i>var</i> = <i>value</i>;<br /> |
223 C() // copy-initializes <i>var</i></code> | 223 C() // copy-initializes <i>var</i></code> |
224 <td>Allows non-static class members to be initialized at their definitions (outs
ide constructors)</td> | 224 <td>Allows non-static class members to be initialized at their definitions (outs
ide constructors)</td> |
225 <td><a href="http://en.cppreference.com/w/cpp/language/data_members">Non-static
data members</a></td> | 225 <td><a href="http://en.cppreference.com/w/cpp/language/data_members">Non-static
data members</a></td> |
226 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev
/zqB-DySA4V0">Discussion thread</a></td> | 226 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev
/zqB-DySA4V0">Discussion thread</a></td> |
(...skipping 13 matching lines...) Expand all Loading... |
240 <td>Indicates that a class or function overrides a base implementation</td> | 240 <td>Indicates that a class or function overrides a base implementation</td> |
241 <td><a href="http://en.cppreference.com/w/cpp/language/override">override specif
ier</a></td> | 241 <td><a href="http://en.cppreference.com/w/cpp/language/override">override specif
ier</a></td> |
242 <td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/
forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td> | 242 <td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/
forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td> |
243 </tr> | 243 </tr> |
244 | 244 |
245 <tr> | 245 <tr> |
246 <td>Range-Based For Loops</td> | 246 <td>Range-Based For Loops</td> |
247 <td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td> | 247 <td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td> |
248 <td>Facilitates a more concise syntax for iterating over the elements of a conta
iner (or a range of iterators) in a <code>for</code> loop</td> | 248 <td>Facilitates a more concise syntax for iterating over the elements of a conta
iner (or a range of iterators) in a <code>for</code> loop</td> |
249 <td><a href="http://en.cppreference.com/w/cpp/language/range-for">Range-based fo
r loop</a></td> | 249 <td><a href="http://en.cppreference.com/w/cpp/language/range-for">Range-based fo
r loop</a></td> |
250 <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/ch
romium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc">Discussion thread</a></td> | 250 <td>As a rule of thumb, use <code>for (const auto& ...)</code>, <code>for (a
uto& ...)</code>, or <code>for (<i>concrete type</i> ...)</code>. For pointe
rs, use <code>for (auto* ...)</code> to make clear that the copy of the loop var
iable 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> |
251 </tr> | 251 </tr> |
252 | 252 |
253 <tr> | 253 <tr> |
254 <td>Rvalue References</td> | 254 <td>Rvalue References</td> |
255 <td><code>T(T&& t)</code> and <code>T& operator=(T&& t)<br/>
<br/> | 255 <td><code>T(T&& t)</code> and <code>T& operator=(T&& t)<br/>
<br/> |
256 template <typename T><br/>void Function(T&& t) { ... }</code></td> | 256 template <typename T><br/>void Function(T&& t) { ... }</code></td> |
257 <td>Reference that only binds to a temporary object</td> | 257 <td>Reference that only binds to a temporary object</td> |
258 <td><a href="http://en.cppreference.com/w/cpp/language/reference#Rvalue_referenc
es">Rvalue references</a></td> | 258 <td><a href="http://en.cppreference.com/w/cpp/language/reference#Rvalue_referenc
es">Rvalue references</a></td> |
259 <td>Only use these to define move constructors and move assignment operators, an
d 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/UnRaO
Rb4TSw">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org
/forum/#!topic/cxx/Q526tkruXpM">Another discussion thread</a></td> | 259 <td>Only use these to define move constructors and move assignment operators, an
d 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/UnRaO
Rb4TSw">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org
/forum/#!topic/cxx/Q526tkruXpM">Another discussion thread</a></td> |
260 </tr> | 260 </tr> |
261 | 261 |
262 <tr> | 262 <tr> |
263 <td>Standard Integers</td> | 263 <td>Standard Integers</td> |
264 <td>Typedefs within <code><stdint.h></code> and <code><inttypes></co
de></td> | 264 <td>Typedefs within <code><stdint.h></code> and <code><inttypes></co
de></td> |
265 <td>Provides fixed-size integers independent of platforms</td> | 265 <td>Provides fixed-size integers independent of platforms</td> |
266 <td><a href="http://en.cppreference.com/w/cpp/header/cstdint">Standard library h
eader <cstdint></a></td> | 266 <td><a href="http://en.cppreference.com/w/cpp/header/cstdint">Standard library h
eader <cstdint></a></td> |
267 <td>Approved without discussion. Required by the <a href="http://google.github.i
o/styleguide/cppguide.html#Integer_Types">Google Style Guide</a>.</td> | 267 <td>Approved without discussion. Required by the <a href="http://google.github.i
o/styleguide/cppguide.html#Integer_Types">Google Style Guide</a>.</td> |
268 </tr> | 268 </tr> |
269 | 269 |
270 <tr> | 270 <tr> |
271 <td>Static Assertions</td> | 271 <td>Static Assertions</td> |
272 <td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td> | 272 <td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td> |
273 <td>Tests compile-time conditions</td> | 273 <td>Tests compile-time conditions</td> |
274 <td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Ass
ertion</a></td> | 274 <td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Ass
ertion</a></td> |
275 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev
/POISBQEhGzU">Discussion thread</a></td> | 275 <td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev
/POISBQEhGzU">Discussion thread</a></td> |
276 </tr> | 276 </tr> |
277 | 277 |
278 <tr> | 278 <tr> |
279 <td>Trailing Return Types</td> | 279 <td>Trailing Return Types</td> |
280 <td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td> | 280 <td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td> |
281 <td>Allows trailing function return value syntax</td> | 281 <td>Allows trailing function return value syntax</td> |
282 <td><a href="http://en.cppreference.com/w/cpp/language/function">Declaring funct
ions</a></td> | 282 <td><a href="http://en.cppreference.com/w/cpp/language/function">Declaring funct
ions</a></td> |
283 <td>Use only where it considerably improves readability. <a href="https://groups
.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion th
read</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Lk
p0nubVd0Q">Another discussion thread</a></td> | 283 <td>Use only where it considerably improves readability. <a href="https://groups
.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion th
read</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Lk
p0nubVd0Q">Another discussion thread</a></td> |
284 </tr> | 284 </tr> |
285 | 285 |
286 <tr> | 286 <tr> |
287 <td>Type Aliases ("using" instead of "typedef")</td> | 287 <td>Type Aliases ("using" instead of "typedef")</td> |
288 <td><code>using <i>new_alias</i> = <i>typename</i></code></td> | 288 <td><code>using <i>new_alias</i> = <i>typename</i></code></td> |
289 <td>Allows parameterized typedefs</td> | 289 <td>Allows parameterized typedefs</td> |
290 <td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias, a
lias template</a></td> | 290 <td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias, a
lias template</a></td> |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 <td><code>long long</code> Type</td> | 557 <td><code>long long</code> Type</td> |
558 <td><code>long long <i>var</i> = <i>value</i>;</code></td> | 558 <td><code>long long <i>var</i> = <i>value</i>;</code></td> |
559 <td>An integer of at least 64 bits</td> | 559 <td>An integer of at least 64 bits</td> |
560 <td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types<
/a></td> | 560 <td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types<
/a></td> |
561 <td>Use a stdint.h type if you need a 64bit number. <a href="https://groups.goog
le.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk">Discussion thread<
/a></td> | 561 <td>Use a stdint.h type if you need a 64bit number. <a href="https://groups.goog
le.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk">Discussion thread<
/a></td> |
562 </tr> | 562 </tr> |
563 | 563 |
564 <tr> | 564 <tr> |
565 <td>Ref-qualified Member Functions</td> | 565 <td>Ref-qualified Member Functions</td> |
566 <td><code>class T {<br /> | 566 <td><code>class T {<br /> |
567 void f() & {}<br /> | 567 void f() & {}<br /> |
568 void f() && {}<br /> | 568 void f() && {}<br /> |
569 };<br /> | 569 };<br /> |
570 t.f(); // first<br /> | 570 t.f(); // first<br /> |
571 T().f(); // second<br /> | 571 T().f(); // second<br /> |
572 std::move(t).f(); // second</code></td> | 572 std::move(t).f(); // second</code></td> |
573 <td>Allows class member functions to only bind to |this| as an rvalue or lvalue.
</td> | 573 <td>Allows class member functions to only bind to |this| as an rvalue or lvalue.
</td> |
574 <td><a href="http://en.cppreference.com/w/cpp/language/member_functions#const-.2
C_volatile-.2C_and_ref-qualified_member_functions">const-, volatile-, and ref-qu
alified member functions</a></td> | 574 <td><a href="http://en.cppreference.com/w/cpp/language/member_functions#const-.2
C_volatile-.2C_and_ref-qualified_member_functions">const-, volatile-, and ref-qu
alified member functions</a></td> |
575 <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/ch
romium.org/forum/#!topic/cxx/gowclr2LPQA">Discussion Thread</a></td> | 575 <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/ch
romium.org/forum/#!topic/cxx/gowclr2LPQA">Discussion Thread</a></td> |
576 </tr> | 576 </tr> |
577 | 577 |
578 <tr> | 578 <tr> |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 <td><a href="http://en.cppreference.com/w/cpp/locale/wstring_convert">std::wstri
ng_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/cod
ecvt_utf8">std::codecvt_utf8</a>, <a href="http://en.cppreference.com/w/cpp/loca
le/codecvt_utf16">std::codecvt_utf16</a>, <a href="http://en.cppreference.com/w/
cpp/locale/codecvt_utf8_utf16">std::codecvt_utf8_utf16</a></td> | 920 <td><a href="http://en.cppreference.com/w/cpp/locale/wstring_convert">std::wstri
ng_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/cod
ecvt_utf8">std::codecvt_utf8</a>, <a href="http://en.cppreference.com/w/cpp/loca
le/codecvt_utf16">std::codecvt_utf16</a>, <a href="http://en.cppreference.com/w/
cpp/locale/codecvt_utf8_utf16">std::codecvt_utf8_utf16</a></td> |
921 <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 use
ful for consuming non-ASCII data.</td> | 921 <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 use
ful for consuming non-ASCII data.</td> |
922 </tr> | 922 </tr> |
923 | 923 |
924 </tbody> | 924 </tbody> |
925 </table> | 925 </table> |
926 | 926 |
927 </div> | 927 </div> |
928 </body> | 928 </body> |
929 </html> | 929 </html> |
OLD | NEW |