Skip to content

Instantly share code, notes, and snippets.

@shininglion
Last active June 26, 2018 02:46
Show Gist options
  • Save shininglion/53a8b5fdbc1272a18cfec79cf18a4412 to your computer and use it in GitHub Desktop.
Save shininglion/53a8b5fdbc1272a18cfec79cf18a4412 to your computer and use it in GitHub Desktop.
prvalue sucks
/*
* =====================================================================================
*
* Filename: prvalue.cpp
*
* Description: test prvalue
*
* Version: 1.0
* Created: 2018/06/26 (yyyy/mm/dd)
* Revision: none
* Compiler: g++ (C++17)
*
* Author: lionking
* Organization: None
* Source: https://www.youtube.com/watch?v=uYDt1gCDxhM&list=PLHTh1InhhwT6bwIpRk0ZbCA0N2p1taxd6&t=0s&index=117
*
* =====================================================================================
*/
#include <iostream>
void bloop(int&&) { std::cout << "int move!\n"; }
void bloop(int const&) { std::cout << "int copy!\n"; }
int const intbar() { return {}; }
struct foo {};
void bloop(foo&&) { std::cout << "foo move!\n"; }
void bloop(foo const&) { std::cout << "foo copy!\n"; }
foo const foobar() { return {}; }
int main()
{
bloop(intbar()); // print "int move!"
bloop(foobar()); // print "foo copy!"
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment