Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: styleguide/c++/c++11.html

Issue 1499293002: Move Rvalue references to the allowed section of the C++11 styleguide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stylervalues: 3rdbug Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 <td>Range-Based For Loops</td> 238 <td>Range-Based For Loops</td>
239 <td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td> 239 <td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td>
240 <td>Facilitates a more concise syntax for iterating over the elements 240 <td>Facilitates a more concise syntax for iterating over the elements
241 of a container (or a range of iterators) in a <code>for</code> loop</td> 241 of a container (or a range of iterators) in a <code>for</code> loop</td>
242 <td><a href="http://en.cppreference.com/w/cpp/language/range-for"> 242 <td><a href="http://en.cppreference.com/w/cpp/language/range-for">
243 Range-based for loop</a></td> 243 Range-based for loop</a></td>
244 <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> 244 <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>
245 </tr> 245 </tr>
246 246
247 <tr> 247 <tr>
248 <td>Rvalue References</td>
249 <td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</cod e><br/>
250 <code>template <typename T>void Function(T&& t) { ... }</code></td>
251 <td>Reference that only binds to a temporary object</td>
252 <td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_referen ces">
253 Rvalue references</a></td>
254 <td>As per the <a href="https://google.github.io/styleguide/cppguide.html#Rvalue _references">Google style guide</a>: Only use these to define move constructors and move assignment operators, and for perfect forwarding.<br/>Most classes shou ld not be copyable, even if movable. Continue to use DISALLOW_COPY_AND_ASSIGN (o r DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND if needed) in most cases. <a href= "https://groups.google.com/a/chromium.org/d/topic/chromium-dev/UnRaORb4TSw">Disc ussion thread</a> and <a href="https://groups.google.com/a/chromium.org/d/topic/ cxx/Q526tkruXpM">discussion thread</a>.
255 <br/><br/>
256 MSVC 2013 has some known bugs with rvalue references:
257 <ul>
258 <li>Exported classes generate copy constructors even if they are not used, which tries to use copy constructors on members. Use DISALLOW_COPY_AND_ASSIGN on the exported class to resolve it.</li>
259 <li>The compiler chooses a T::(T&) constructor before T::(T&&). However copy con structors should be written as T::T(const T&) and these are prioritized correctl y.</li>
260 <li>The compile does not create default move constructors, either implicitly or with the =default keyword. You must provide such constructors explicitly to crea te them.</li>
Nico 2015/12/07 19:34:46 s/the compile/the compiler/
danakj 2015/12/07 19:36:07 Yaaa oops. I typod in my patchset description abou
261 </ul>
262 </td>
263 </tr>
264
265 <tr>
248 <td>Standard Integers</td> 266 <td>Standard Integers</td>
249 <td>Typedefs within <code>&lt;stdint.h&gt;</code> 267 <td>Typedefs within <code>&lt;stdint.h&gt;</code>
250 and <code>&lt;inttypes&gt;</code></td> 268 and <code>&lt;inttypes&gt;</code></td>
251 <td>Provides fixed-size integers independent of platforms</td> 269 <td>Provides fixed-size integers independent of platforms</td>
252 <td><a href="http://www.cplusplus.com/reference/cstdint/"> 270 <td><a href="http://www.cplusplus.com/reference/cstdint/">
253 &lt;stdint.h&gt; (cstdint)</a></td> 271 &lt;stdint.h&gt; (cstdint)</a></td>
254 <td>Already in common use in the codebase. Approved without discussion.</td> 272 <td>Already in common use in the codebase. Approved without discussion.</td>
255 </tr> 273 </tr>
256 274
257 <tr> 275 <tr>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 <td>Wraps an iterator so that it moves objects instead of copying them.</td> 366 <td>Wraps an iterator so that it moves objects instead of copying them.</td>
349 <td><a href="http://en.cppreference.com/w/cpp/iterator/make_move_iterator">std:: make_move_iterator</a></td> 367 <td><a href="http://en.cppreference.com/w/cpp/iterator/make_move_iterator">std:: make_move_iterator</a></td>
350 <td>Useful to move objects between containers that contain move-only types like <code>scoped_ptr</code>. <a href="https://groups.google.com/a/chromium.org/forum /#!topic/cxx/lccnUljOHQU">Discussion thread</a></td> 368 <td>Useful to move objects between containers that contain move-only types like <code>scoped_ptr</code>. <a href="https://groups.google.com/a/chromium.org/forum /#!topic/cxx/lccnUljOHQU">Discussion thread</a></td>
351 </tr> 369 </tr>
352 370
353 <tr> 371 <tr>
354 <td>Move Semantics</td> 372 <td>Move Semantics</td>
355 <td><code>std::move()</code></td> 373 <td><code>std::move()</code></td>
356 <td>Facilitates efficient move operations</td> 374 <td>Facilitates efficient move operations</td>
357 <td><a href="http://en.cppreference.com/w/cpp/utility/move"><code>std::move</cod e> reference</a></td> 375 <td><a href="http://en.cppreference.com/w/cpp/utility/move"><code>std::move</cod e> reference</a></td>
358 <td>Note: std::move() is allowed but writing your own move constructors is still only allowed in exceptional cases for now, see 'Rvalue References (and Move Sem antics)'. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_ dWFxJFdbM'>Discussion thread</a></td> 376 <td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJF dbM'>Discussion thread</a></td>
359 </tr> 377 </tr>
360 378
361 <tr> 379 <tr>
362 <td>Type Traits</td> 380 <td>Type Traits</td>
363 <td>Class templates within <code>&lt;type_traits&gt;</code></td> 381 <td>Class templates within <code>&lt;type_traits&gt;</code></td>
364 <td>Allows compile-time inspection of the properties of types</td> 382 <td>Allows compile-time inspection of the properties of types</td>
365 <td><a href="http://en.cppreference.com/w/cpp/header/type_traits"> 383 <td><a href="http://en.cppreference.com/w/cpp/header/type_traits">
366 Standard library header &lt;type_traits&gt;</a></td> 384 Standard library header &lt;type_traits&gt;</a></td>
367 <td>Note that not all type traits are available on all platforms (eg std::underl ying_type doesn't work in libstdc++4.6). Use judiciously. <a href='https://group s.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a> </td> 385 <td>Note that not all type traits are available on all platforms (eg std::underl ying_type doesn't work in libstdc++4.6). Use judiciously. <a href='https://group s.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a> </td>
368 </tr> 386 </tr>
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 <td>Raw String Literals</td> 472 <td>Raw String Literals</td>
455 <td><code>string <i>var</i>=R&quot;(<i>raw_string</i>)&quot;;</code></td> 473 <td><code>string <i>var</i>=R&quot;(<i>raw_string</i>)&quot;;</code></td>
456 <td>Allows a string to be encoded without any escape 474 <td>Allows a string to be encoded without any escape
457 sequences, easing parsing in regex expressions, for example</td> 475 sequences, easing parsing in regex expressions, for example</td>
458 <td><a href="http://en.cppreference.com/w/cpp/language/string_literal"> 476 <td><a href="http://en.cppreference.com/w/cpp/language/string_literal">
459 string literal</a></td> 477 string literal</a></td>
460 <td>Causes incorrect line numbers in MSVS2013 and gcc. Reevaluate once that work s. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ 2kWQHbbuMHI">Discussion thread</a></td> 478 <td>Causes incorrect line numbers in MSVS2013 and gcc. Reevaluate once that work s. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ 2kWQHbbuMHI">Discussion thread</a></td>
461 </tr> 479 </tr>
462 480
463 <tr> 481 <tr>
464 <td>Rvalue References (and Move Semantics)</td>
465 <td><code>T(T&amp;&amp; t)</code> and <code>T&amp; operator=(T&amp;&amp; t)</cod e></td>
466 <td>Reference that only binds to a temporary object</td>
467 <td><a href="http://en.cppreference.com/w/cpp/language/references#Rvalue_referen ces">
468 Rvalue references</a></td>
469 <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/chrom ium.org/d/topic/chromium-dev/UnRaORb4TSw">Discussion thread</a></td>
470 </tr>
471
472 <tr>
473 <td>(Uniform) Initialization Syntax</td> 482 <td>(Uniform) Initialization Syntax</td>
474 <td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></t d> 483 <td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></t d>
475 <td>Allows any object of primitive, aggregate or class 484 <td>Allows any object of primitive, aggregate or class
476 type to be initialized using brace syntax</td> 485 type to be initialized using brace syntax</td>
477 <td>TODO: documentation link</td> 486 <td>TODO: documentation link</td>
478 <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/#!topi c/chromium-dev/GF96FshwHLw">Discussion thread</a></td> 487 <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/#!topi c/chromium-dev/GF96FshwHLw">Discussion thread</a></td>
479 </tr> 488 </tr>
480 489
481 <tr> 490 <tr>
482 <td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td> 491 <td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td>
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 C++ Style Guide</a>. However, may be useful for 1072 C++ Style Guide</a>. However, may be useful for
1064 consuming non-ASCII data.</td> 1073 consuming non-ASCII data.</td>
1065 </tr> 1074 </tr>
1066 1075
1067 </tbody> 1076 </tbody>
1068 </table> 1077 </table>
1069 1078
1070 </div> 1079 </div>
1071 </body> 1080 </body>
1072 </html> 1081 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698