[Cs3] time of biding at bind
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Mar 2 15:25:07 EST 2021
CS3 students,
This is regarding the question as to when std::bind() determines its
bound parameters: at the time of binding or invocation. As as
suspected, it is the same as for labmdas: at the time of binding.
The below program prints: func(abc) not func(xyz)
Thanks,
--
Mikhail
#include <iostream>
#include <string>
#include <functional>
using std::cout; using std::endl; using std::string;
// function to use to demo binding
void func(const string& str){
cout << "func(" << str << ")" << endl;
}
int main(){
// bind argument to a fixed value
string str = "abc";
auto f1 = bind(func, str);
str = "xyz"; // change string value
f1(); // change does not stick
}
More information about the cs3
mailing list