Main Content
AUTOSAR C++14 Rule A18-9-1
The std::bind shall not be used
Description
Rule Definition
The std::bind shall not be used.
Rationale
std::bind
takes a callable object, such as a function object, and
produces a forwarding call wrapper for this object. Calling the wrapper invokes the object
with some of the object arguments bound to arguments you specify in the wrapper. For
instance, in this code snippet, foo
is called through
bar
with the first (second) argument of bar
bound to
the second (first) argument of foo
.
int foo(int, int); auto bar = std::bind(foo, _2, _1); bar(10, 20); //call to foo(20, 10)
std::bind
results in a less readable function
call. A developer that is unfamiliar with foo
would need to see the
declaration of foo
to understand how to pass arguments to
bar
, and might confuse one function parameter with another. In
addition, a compiler is less likely to inline a function that you create using
std::bind
.Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: 18 Language Support Library |
Category: Required, Automated |
Version History
Introduced in R2019b