Consider the following snippet
#include <iostream>
#include <functional>
using callback = std::function<double (double, double)>;
double sum (double a, double b) {
return a + b;
}
int main (int argc, char *argv[]) {
// Shouldn't this leave sum() in an invalid state?
auto c = std::move(sum);
std::cout << c(4, 5) << std::endl;
std::cout << sum(4, 5) << std::endl;
return EXIT_SUCCESS;
}
I'm converting sum
to an rvalue reference, store that in c
, and invoke both functions with no noticeable misbehaviors. Why is that? Shouldn't std::move
leave sum
in an invalid state?