Skip to content

Instantly share code, notes, and snippets.

@kalman5
Last active January 25, 2020 08:44
Show Gist options
  • Save kalman5/30b8d00f3f56a6eb7cc2be187dd0ef5d to your computer and use it in GitHub Desktop.
Save kalman5/30b8d00f3f56a6eb7cc2be187dd0ef5d to your computer and use it in GitHub Desktop.
struct Foo {
// used when Foo instance is an l-value
void operator()() const & {
std::cout << "l-value" << "\n";
}
// used when Foo isntance is an r-value
void operator()() const && {
std::cout << "r-value" << "\n";
}
};
Foo f;
f(); // First operator is used
Foo()(); // Second operator is used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment