diff --git a/.clang-tidy b/.clang-tidy index 93e4a7c4..6df242d9 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,6 +4,7 @@ Checks: ' -*, llvm-namespace-comment, modernize-use-override, +readability-container-size-empty, ' HeaderFilterRegex: 'pybind11/.*h' diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 47a54aff..85875e90 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -59,7 +59,7 @@ public: Py_CLEAR(ptr); // A heuristic to reduce the stack's capacity (e.g. after long recursive calls) - if (stack.capacity() > 16 && stack.size() != 0 && stack.capacity() / stack.size() > 2) + if (stack.capacity() > 16 && !stack.empty() && stack.capacity() / stack.size() > 2) stack.shrink_to_fit(); } @@ -163,7 +163,7 @@ inline const std::vector &all_type_info(PyTypeObject *type) */ PYBIND11_NOINLINE inline detail::type_info* get_type_info(PyTypeObject *type) { auto &bases = all_type_info(type); - if (bases.size() == 0) + if (bases.empty()) return nullptr; if (bases.size() > 1) pybind11_fail("pybind11::detail::get_type_info: type has multiple pybind11-registered bases"); diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 8d36744f..b4a11c0a 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -592,7 +592,7 @@ inline PyObject* make_new_python_type(const type_record &rec) { auto &internals = get_internals(); auto bases = tuple(rec.bases); - auto base = (bases.size() == 0) ? internals.instance_base + auto base = (bases.empty()) ? internals.instance_base : bases[0].ptr(); /* Danger zone: from now (and until PyType_Ready), make sure to @@ -616,7 +616,7 @@ inline PyObject* make_new_python_type(const type_record &rec) { type->tp_doc = tp_doc; type->tp_base = type_incref((PyTypeObject *)base); type->tp_basicsize = static_cast(sizeof(instance)); - if (bases.size() > 0) + if (!bases.empty()) type->tp_bases = bases.release().ptr(); /* Don't inherit base __init__ */ diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 866a62dc..9f1736fd 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -626,7 +626,7 @@ protected: } // 3. Check everything was consumed (unless we have a kwargs arg) - if (kwargs && kwargs.size() > 0 && !func.has_kwargs) + if (kwargs && !kwargs.empty() && !func.has_kwargs) continue; // Unconsumed kwargs, but no py::kwargs argument to accept them // 4a. If we have a py::args argument, create a new tuple with leftovers @@ -814,7 +814,7 @@ protected: } if (kwargs_in) { auto kwargs = reinterpret_borrow(kwargs_in); - if (kwargs.size() > 0) { + if (!kwargs.empty()) { if (some_args) msg += "; "; msg += "kwargs: "; bool first = true;