rspec/rules/S1704/rule.adoc
2021-01-26 14:30:57 +01:00

29 lines
612 B
Plaintext

Rvalue references were introduced as part of {cpp}11. They are thus a new feature of the language, and are not yet widely understood. Using them is complicated, and code using rvalue references may be difficult to understand.
== Noncompliant Code Example
----
std::vector<int> return_vector(void)
{
std::vector<int> tmp {1,2,3,4,5};
return tmp;
}
std::vector<int> &&rval_ref = return_vector(); // Noncompliant
----
== Compliant Solution
----
std::vector<int> return_vector(void)
{
std::vector<int> tmp {1,2,3,4,5};
return tmp;
}
const std::vector<int>& rval_ref = return_vector();
----