[PATCH] [Clang Tidy]: Use shrink_to_fit instead of copy and swap trick.

Gábor Horváth xazax.hun at gmail.com
Wed Jan 21 03:35:03 PST 2015


Hi alexfh,

The \c shrink_to_fit() method is more readable and more effective than
the copy and swap trick to reduce the capacity of a shrinkable container.
Note that, the \c shrink_to_fit() method is only available in C++11 and up.

Example:

std::vector<int>(v).swap(v); will be replaced with v.shrink_to_fit();

There was already a checker which targeted C++11, however it did not contain any check, which standard is used during the analysis. Maybe a check should be added to suppress C++11 specific warnings when clang tidy is invoked in C++03 mode?

http://reviews.llvm.org/D7087

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/ShrinkToFitCheck.cpp
  clang-tidy/readability/ShrinkToFitCheck.h
  test/clang-tidy/readability-shrink-to-fit.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7087.18495.patch
Type: text/x-patch
Size: 7545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150121/fd7ea7a8/attachment.bin>


More information about the cfe-commits mailing list