From 25deeba3b58266491937e3bcf8356f7c1b894eba Mon Sep 17 00:00:00 2001 From: Bjarne Stroustrup Date: Tue, 19 Jul 2016 16:49:44 -0400 Subject: [PATCH] T.140 --- CppCoreGuidelines.md | 55 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 005c239..19c80f8 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -1,6 +1,6 @@ # C++ Core Guidelines -July 18, 2016 +July 19, 2016 Editors: @@ -12795,7 +12795,7 @@ Metaprogramming rule summary: Other template rules summary: -* [T.140: Name all nontrivial operations](#Rt-name) +* [T.140: Name all operations with potential for reuse](#Rt-name) * [T.141: Use an unnamed lambda if you need a simple function object in one place only](#Rt-lambda) * [T.142: Use template variables to simplify notation](#Rt-var) * [T.143: Don't write unintentionally nongeneric code](#Rt-nongeneric) @@ -14568,7 +14568,7 @@ Write your own "advanced TMP support" only if you really have to. ## Other template rules -### T.140: Name all nontrivial operations +### T.140: Name all operations with potential for reuse ##### Reason @@ -14576,17 +14576,53 @@ Documentation, readability, opportunity for reuse. ##### Example - ??? + struct Rec { + string name; + string addr; + int id; // unique identifier + }; -##### Example, good + bool same(const Rec& a, const Rec& b) + { + return a.id==b.id; + } - ??? + vector find_id(const string& name); // find all records for "name" + + auto x = find_if(vr.begin(),vr.end(), + [&](Rec& r) { + int (r.name.size()!=n.size()) return false; // name to compare to is in n + for (int i=0; i 100; }); + -**Exception**: Naming a lambda can be useful for clarity even if it is used only once +##### Exception + +Naming a lambda can be useful for clarity even if it is used only once. ##### Enforcement