Created
April 7, 2017 19:49
-
-
Save ajvengo/a7c7cc6f9a8ee0a6fffa19b2d07b53c4 to your computer and use it in GitHub Desktop.
Test copyable vs movable arguments for overloaded functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <iostream> | |
using namespace std; | |
// must be used for movable arguments only | |
void f(int&& x) { | |
using X = decltype(x); | |
cout << __PRETTY_FUNCTION__ << ' ' << std::is_rvalue_reference<X>::value << endl; | |
} | |
// must be used for copyable arguments only | |
void f(const int& x) { | |
using X = decltype(x); | |
cout << __PRETTY_FUNCTION__ << ' ' << std::is_rvalue_reference<X>::value << endl; | |
} | |
int main() { | |
int i = 2; | |
int& iref = i; | |
const int& const_iref = i; | |
f(4); | |
f(4 + 2); | |
f(i); | |
f(std::move(i)); | |
f(iref); | |
f(std::move(iref)); | |
f(const_iref); | |
f(std::move(const_iref)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment