Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/modernize/min-max-use-initializer-list.rst

raw
1 .. title:: clang-tidy - modernize-min-max-use-initializer-list
2
3 modernize-min-max-use-initializer-list
4 ======================================
5
6 Replaces nested ``std::min`` and ``std::max`` calls with an initializer list
7 where applicable.
8
9 For instance, consider the following code:
10
11 .. code-block:: cpp
12
13 int a = std::max(std::max(i, j), k);
14
15 The check will transform the above code to:
16
17 .. code-block:: cpp
18
19 int a = std::max({i, j, k});
20
21 Performance Considerations
22 ==========================
23
24 While this check simplifies the code and makes it more readable, it may cause
25 performance degradation for non-trivial types due to the need to copy objects
26 into the initializer list.
27
28 To avoid this, it is recommended to use `std::ref` or `std::cref` for
29 non-trivial types:
30
31 .. code-block:: cpp
32
33 std::string b = std::max({std::ref(i), std::ref(j), std::ref(k)});
34
35 Options
36 =======
37
38 .. option:: IncludeStyle
39
40 A string specifying which include-style is used, `llvm` or `google`. Default
41 is `llvm`.
42
43 .. option:: IgnoreNonTrivialTypes
44
45 A boolean specifying whether to ignore non-trivial types. Default is `true`.
46
47 .. option:: IgnoreTrivialTypesOfSizeAbove
48
49 An integer specifying the size (in bytes) above which trivial types are
50 ignored. Default is `32`.