Consider this code,
#include <iostream>
#include <functional>
void pacifist()
{
std::cout << "I don't get involved in arguments. I'm a pacifist.\n";
}
int main() {
auto x = std::bind(pacifist);
x();
x(5);
x(5, 10);
x(5, 10, 15);
}
And it compiles fine; It even starts, but all calls are x
calls pacifist
! ( online demo ):
$ clang ++ -std = C ++ 14 -O2 -Wall -pedantic -pthread main.cpp && & & &. / a.out
I don't get involved in arguments. I'm a pacifist.
I don't get involved in arguments. I'm a pacifist.
I don't get involved in arguments. I'm a pacifist.
I don't get involved in arguments. I'm a pacifist.
Why is it std::bind
designed to work with arguments in this case? Do they even make sense? Don't they mislead programmers? It works with g ++ .
std::bind
the documentation in cppreference says
If some arguments provided in the g () call are not matched with any placeholders stored in g, unused arguments are evaluated and discarded.
, ? ? .
, :
void call(std::function<void(int)> fun)
{
fun(5);
}
call(std::bind(pacifist));
, , . , std::function<void(int)>
: " int
" , , int; , , int
.