From e67ac2a3c464b9bbcb1e4c8c217aed935bde3836 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 25 Sep 2016 04:26:58 +0200 Subject: Add section on modernization to C++ style guide --- cxx-style.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cxx-style.txt b/cxx-style.txt index 64af573..ec2b24e 100644 --- a/cxx-style.txt +++ b/cxx-style.txt @@ -6,7 +6,13 @@ better) "clever" code that tries to avoid extra copies, allocations, etc. See also the note on small value optimization. -1. Almost never auto +1. Modernization + +- use override +- consider constexpr for inline functions (e.g., enum class bitmask operators) +- consider noexcept + +2. Almost never auto Using auto instead of the actual type often makes code harder to understand. You may (but don't have to) use auto when (a) the type is spelled out on the @@ -18,7 +24,7 @@ Examples of the latter are lambda initializations, iterator initializations (e.g, from begin()), and some cases of pair initialization (e.g, from container's insert()). -2. Almost never brace-initialization +3. Almost never brace-initialization We only use brace-initialization syntax when initializing an aggregate or a container. We can also use it for an aggregate-like initialization of an @@ -47,7 +53,7 @@ struct foo string s = string (123, 's'); }; -3. Many performance-critical standard types are "small object optimized" +4. Many performance-critical standard types are "small object optimized" For example, across all the implementations that we care, std::string can hold at least 15 characters without allocation. Similarly, std::function can hold a -- cgit v1.1