Rule A18-9-1 (required, implementation, automated)

The std::bind shall not be used.

Rationale

Using the std::bind function makes the function call less readable and may lead to the developer confusing one function parameter with another. Also, compilers are less likely to inline the functions that are created using std::bind. It is recommended to use lambda expressions instead.

Example

// $Id: A18-9-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <functional>
class A
{
// Implementation
};
void Fn(A const& a, double y) noexcept
{
// Implementation
}
void F1() noexcept
{
double y = 0.0;
auto function = std::bind(&Fn, std::placeholders::_1, y); // Non-compliant
// ...
A const a{};
function(a);
}
void F2() noexcept
{
auto lambda = [](A const& a) -> void {
double y = 0.0;
Fn(a, y);
}; // Compliant
// ...
A const a{};
lambda(a);
}

See also

Effective Modern C++ [13]: Item 34: Prefer lambdas to std::bind