Skip to content

Instantly share code, notes, and snippets.

@terrelln
Last active June 21, 2016 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrelln/5d15b7f6018fabd25c172e9a7b8d2c83 to your computer and use it in GitHub Desktop.
Save terrelln/5d15b7f6018fabd25c172e9a7b8d2c83 to your computer and use it in GitHub Desktop.
#include <iostream>
struct skeleton {
skeleton() { std::cout << "skeleton()" << std::endl; }
skeleton(const skeleton&) { std::cout << "skeleton(const skeleton&)" << std::endl; }
skeleton(skeleton&) { std::cout << "skeleton(skeleton&)" << std::endl; }
skeleton(const skeleton&&) { std::cout << "skeleton(const skeleton&&)" << std::endl; }
skeleton(skeleton&&) { std::cout << "skeleton(skeleton&&)" << std::endl; }
skeleton& operator=(const skeleton&) {
std::cout << "skeleton& operator=(const skeleton&)" << std::endl;
return *this;
}
skeleton& operator=(skeleton&) {
std::cout << "skeleton& operator=(skeleton&)" << std::endl;
return *this;
}
skeleton& operator=(const skeleton&&) {
std::cout << "skeleton& operator=(const skeleton&&)" << std::endl;
return *this;
}
skeleton& operator=(skeleton&&) {
std::cout << "skeleton& operator=(skeleton&&)" << std::endl;
return *this;
}
void foo() const& { std::cout << "void foo() const&" << std::endl; }
void foo() & { std::cout << "void foo() &" << std::endl; }
void foo() const&& { std::cout << "void foo() const&&" << std::endl; }
void foo() && { std::cout << "void foo() &&" << std::endl; }
static void bar(const skeleton&) { std::cout << "static void bar(const skeleton&)" << std::endl; }
static void bar(skeleton&) { std::cout << "static void bar(skeleton&)" << std::endl; }
static void bar(const skeleton&&) { std::cout << "static void bar(const skeleton&&)" << std::endl; }
static void bar(skeleton&&) { std::cout << "static void bar(skeleton&&)" << std::endl; }
~skeleton() { std::cout << "~skeleton()" << std::endl; }
};
void fn(skeleton x) { x.foo(); }
void gn(skeleton &&x) {
auto y = std::move(x);
y.foo();
}
int main() {
fn(skeleton{});
gn(skeleton{});
skeleton x;
fn(std::move(x));
gn(std::move(x));
}
/** OUTPUT:
skeleton()
void foo() &
~skeleton()
skeleton()
skeleton(skeleton&&)
void foo() &
~skeleton()
~skeleton()
skeleton()
skeleton(skeleton&&)
void foo() &
~skeleton()
skeleton(skeleton&&)
void foo() &
~skeleton()
~skeleton()
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment