Using ``++size()++`` or ``++count()++`` method to test for emptiness works, but using ``++empty()++`` or ``++is_empty()++`` methods makes the code more readable and can be more performant. The time complexity of any ``++empty()++``/``++is_empty()++`` method implementation should be ``++O(1)++`` whereas some implementations of ``++size()++`` or ``++count()++`` can be ``++O(n)++``.

== Noncompliant Code Example

----
void fun(const std::vector<int> &myVector) {
  if (myVector.size() == 0) { // Noncompliant
    // do something
  }
}
----

== Compliant Solution

----
void fun(const std::vector<int> &myVector) {
  if (myVector.empty()) {
    // do something
  }
}
----

== See

* https://github.com/isocpp/CppCoreGuidelines/blob/c553535fb8dda2839d13ab5f807ffbc66b63d67b/CppCoreGuidelines.md#enforcement-324[{cpp} Core Guidelines - T.143] - Don't write unintentionally nongeneric code

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
