{"action":"created","issue":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1603","labels_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1603/labels{/name}","comments_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1603/comments","events_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1603/events","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1603","id":101630199,"number":1603,"title":"Modernize the code base to C++11 standards and beyond.","user":{"login":"daniel-j-h","id":527241,"avatar_url":"https://avatars.githubusercontent.com/u/527241?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-j-h","html_url":"https://github.com/daniel-j-h","followers_url":"https://api.github.com/users/daniel-j-h/followers","following_url":"https://api.github.com/users/daniel-j-h/following{/other_user}","gists_url":"https://api.github.com/users/daniel-j-h/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-j-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-j-h/subscriptions","organizations_url":"https://api.github.com/users/daniel-j-h/orgs","repos_url":"https://api.github.com/users/daniel-j-h/repos","events_url":"https://api.github.com/users/daniel-j-h/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-j-h/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-18T10:59:10Z","updated_at":"2015-08-19T09:57:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/pulls/1603","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1603","diff_url":"https://github.com/Project-OSRM/osrm-backend/pull/1603.diff","patch_url":"https://github.com/Project-OSRM/osrm-backend/pull/1603.patch"},"body":"Apply `clang-modernize` (based on Clang 3.6) transformations to the\r\ncodebase while making sure to support Clang>=3.4 and GCC>=4.8.\r\n\r\nWe apply the transformations in parallel to speed up the quite\r\ntime consuming process, and use our `clang-format` style file\r\nto automatically format the code respecting our coding conventions.\r\n\r\nWe use the following self-explanatory transformations:\r\n\r\n* AddOverride\r\n* LoopConvert\r\n* PassByValue\r\n* ReplaceAutoPtr\r\n* UseAuto\r\n* UseNullptr\r\n\r\nThis required a `compile_commands.json` compilation database, e.g.\r\n\r\n    ccmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1\r\n\r\nfor CMake or check Bear for a Makefile based solution (or even Ninja).\r\n\r\n    git ls-files -x '*.cpp|*.h' | \\\r\n      xargs -I{} -P $(nproc) clang-modernize -p build -final-syntax-check -format -style=file -summary -for-compilers=clang-3.4,gcc-4.8 -include . -exclude third_party {}\r\n\r\nBoom!\r\n\r\nReferences:\r\n\r\n* http://clang.llvm.org/extra/clang-modernize.html\r\n* http://clang.llvm.org/extra/ModernizerUsage.html"},"comment":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/comments/132522357","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1603#issuecomment-132522357","issue_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1603","id":132522357,"user":{"login":"daniel-j-h","id":527241,"avatar_url":"https://avatars.githubusercontent.com/u/527241?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-j-h","html_url":"https://github.com/daniel-j-h","followers_url":"https://api.github.com/users/daniel-j-h/followers","following_url":"https://api.github.com/users/daniel-j-h/following{/other_user}","gists_url":"https://api.github.com/users/daniel-j-h/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-j-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-j-h/subscriptions","organizations_url":"https://api.github.com/users/daniel-j-h/orgs","repos_url":"https://api.github.com/users/daniel-j-h/repos","events_url":"https://api.github.com/users/daniel-j-h/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-j-h/received_events","type":"User","site_admin":false},"created_at":"2015-08-19T09:57:40Z","updated_at":"2015-08-19T09:57:40Z","body":"The arguments for passing sink values by value is explained in detail in \"Modern Effective C++\", Item 26 and Item 27. Here's a article that basically has more or less the same explanations:\r\n\r\n> https://dzone.com/articles/c-sink-parameter-passing\r\n\r\nThe reasoning goes like this:\r\n\r\nYou want to provide the option to \"steal\" from an rvalue if the user passes one in. In the lvalue case you need a copy anyway. That is, the optimal solution would be to write both `T(const U&)` and `T(U&&)`.\r\n\r\nThis is fine for a single parameter, for more there is a space explosion, as you would have to write all combinations, such as `T(const U&, const V&)`,`T(U&&, const V&)` and so on.\r\n\r\nYou could use what Scott Meyer's calls \"universal references\", that is `T&&` in a type-deducing context, but this has downsides of 1/ requiring a type-deducing context, 2/ being favoured by the compiler over copy constructors for non-const lvalues, 3/ ugly error messages.\r\n\r\nIn contrast passing by value solves the problem in the following way:\r\n\r\nIf it's an rvalue we move from it, if it's an lvalue we do a copy (that we need anyway). This requires the move to be rather cheap. The standard provides a few features that make it cheap even in cases where the type is not moveable:\r\n\r\n* [Copy Elision](\r\nhttp://en.cppreference.com/w/cpp/language/copy_elision): the copy / move from a temporary into the member attribute is **ommitted** --- if you don't want this you have to disable this with a compiler switch (smth. smth. fno-elision)\r\n* (Named)RVO: even without move semantics NRVO kicks in, constructing objects in place\r\n\r\nIn our particular situation (i.e. primitive types) there should be no difference."}}