rspec/rules/S6028/cfamily/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

59 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
Using ``++<algorithm>++`` header non-modifying operations ``++all_of++``, ``++none_of++`` and ``++any_of++`` allows to simplify the code and make it less error-prone.
When using versions of the standard between {cpp}11 and {cpp}17 included you should use:
* ``++std::all_of++``: return ``++true++`` if all elements in the given range are matching the given predicate, ``++false++`` otherwise
* ``++std::none_of++``: return ``++true++`` if no elements in the given range are matching the given predicate, ``++false++`` otherwise
* ``++std::any_of++``: return ``++true++`` if at least one element in the given range is matching the given predicate, ``++false++`` otherwise
In {cpp}20,  range-based alternatives have been introduced:
* ``++std::ranges::all_of++``
* ``++std::ranges::none_of++``
* ``++std::ranges::any_of++``
This rule will detect common patterns that can be replaced by these three STL algorithms.
=== Noncompliant code example
[source,cpp]
----
bool asDesired(const int v);
bool areAllDesired(std::vector<int> values) {
for (int val : values) { // Noncompliant, replace it by a call to std::all_of
if (!asDesired(val)) {
return false;
}
}
return true;
}
----
=== Compliant solution
[source,cpp]
----
bool asDesired(const int v);
bool areAllDesired2(std::vector<int> values) {
return std::all_of(std::begin(values), std::end(values), asDesired);
}
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== on 19 Nov 2020, 14:39:48 Abbas Sabra wrote:
Implemented as part of S5566
endif::env-github,rspecator-view[]