Skip to content

Instantly share code, notes, and snippets.

@mklca
Created May 26, 2020 23:10
Show Gist options
  • Save mklca/98af8be39ebf91e822f89bd83f6cd43b to your computer and use it in GitHub Desktop.
Save mklca/98af8be39ebf91e822f89bd83f6cd43b to your computer and use it in GitHub Desktop.
Attempting to build a call-at-most-once functor
#include <iostream>
#include <utility>
using namespace std;
struct F {
F() = default;
F(const F&) = delete;
F& operator =(const F&) = delete;
void operator()() && {
cout << "In (F&&)()\n";
}
};
int main() {
F f;
// f(); error: No matching function for call to object of type 'F'
move(f)();
move(f)(); // Clang-Tidy: 'f' used after it was moved
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment