brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 624718a Raw
40 lines · plain
1.. title:: clang-tidy - modernize-use-transparent-functors2 3modernize-use-transparent-functors4==================================5 6Prefer transparent functors to non-transparent ones. When using transparent7functors, the type does not need to be repeated. The code is easier to read,8maintain and less prone to errors. It is not possible to introduce unwanted9conversions.10 11.. code-block:: c++12 13    // Non-transparent functor14    std::map<int, std::string, std::greater<int>> s;15 16    // Transparent functor.17    std::map<int, std::string, std::greater<>> s;18 19    // Non-transparent functor20    using MyFunctor = std::less<MyType>;21 22It is not always a safe transformation though. The following case will be23untouched to preserve the semantics.24 25.. code-block:: c++26 27    // Non-transparent functor28    std::map<const char *, std::string, std::greater<std::string>> s;29 30Options31-------32 33.. option:: SafeMode34 35  If the option is set to `true`, the check will not diagnose cases where36  using a transparent functor cannot be guaranteed to produce identical results37  as the original code. The default value for this option is `false`.38 39This check requires using C++14 or higher to run.40