You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2015/04/07 13:11:23 UTC

mesos git commit: Additonal use case for "auto" in C++ style guide: shared pointer creation.

Repository: mesos
Updated Branches:
  refs/heads/master 91861bd20 -> 94d5c3a8d


Additonal use case for "auto" in C++ style guide: shared pointer creation.

Explicitly allows auto declarations for shared pointer creations.
Example:
  auto nameList = shared_ptr<list<string>>(new list<string>());
Here the type on the left is already explicitly stated on the right.
This replaces
  shared_ptr<list<string>> nameList = shared_ptr<list<string>>(new list<string>());
where we needlessly write the same type twice.

Review: https://reviews.apache.org/r/30792


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/94d5c3a8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/94d5c3a8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/94d5c3a8

Branch: refs/heads/master
Commit: 94d5c3a8d0a46db8a1309499788638b6a8c325d9
Parents: 91861bd
Author: Bernd Mathiske <be...@mesosphere.io>
Authored: Tue Apr 7 13:09:34 2015 +0200
Committer: Till Toenshoff <to...@me.com>
Committed: Tue Apr 7 13:09:34 2015 +0200

----------------------------------------------------------------------
 docs/mesos-c++-style-guide.md | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/94d5c3a8/docs/mesos-c++-style-guide.md
----------------------------------------------------------------------
diff --git a/docs/mesos-c++-style-guide.md b/docs/mesos-c++-style-guide.md
index 439fe12..de1b93e 100644
--- a/docs/mesos-c++-style-guide.md
+++ b/docs/mesos-c++-style-guide.md
@@ -92,7 +92,8 @@ We still support older compilers. The whitelist of supported C++11 features is:
 
 * Static assertions.
 * Multiple right angle brackets.
-* Type inference (`auto` and `decltype`). The main goal is to increase code readability. Here are several examples:
+* Type inference (`auto` and `decltype`). The main goal is to increase code readability. This is safely the case if the exact same type omitted on the left is already fully stated on the right.
+* Here are several examples:
 
 <pre>
 // 1: OK.
@@ -100,7 +101,12 @@ const auto& i = values.find(keys.front());
 // Compare with
 const typename map::iterator& i = values.find(keys.front());
 
-// 2: Don't use.
+// 2: OK.
+auto names = shared_ptr<list<string>>(new list<string>());
+// Compare with
+shared_ptr<list<string>> names = shared_ptr<list<string>>(new list<string>());
+
+// 3: Don't use.
 auto authorizer = LocalAuthorizer::create(acls);
 // Compare with
 Try&lt;Owned&lt;LocalAuthorizer>> authorizer = LocalAuthorizer::create();