brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · cc012fd Raw
38 lines · plain
1.. title:: clang-tidy - readability-container-size-empty2 3readability-container-size-empty4================================5 6 7Checks whether a call to the ``size()``/``length()`` method can be replaced8with a call to ``empty()``.9 10The emptiness of a container should be checked using the ``empty()`` method11instead of the ``size()``/``length()`` method. It shows clearer intent to use12``empty()``. Furthermore some containers (for example, a ``std::forward_list``)13may implement the ``empty()`` method but not implement the ``size()`` or14``length()`` method. Using ``empty()`` whenever possible makes it easier to15switch to another container in the future.16 17The check issues warning if a container has ``empty()`` and ``size()`` or18``length()`` methods matching following signatures:19 20.. code-block:: c++21 22  size_type size() const;23  size_type length() const;24  bool empty() const;25 26`size_type` can be any kind of integer type.27 28Options29-------30 31.. option:: ExcludedComparisonTypes32 33    A semicolon-separated list of regular expressions matching class names for34    which the check will ignore comparisons of objects with default-constructed35    objects of the same type. If a class is listed here, the check will not36    suggest using ``empty()`` instead of such comparisons for objects of that37    class. Default value is: `::std::array`.38