Last active
August 29, 2015 14:25
-
-
Save beyondwdq/47a7224fe54d257dac47 to your computer and use it in GitHub Desktop.
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 <iostream> | |
template <typename T> | |
struct ShowType | |
{ | |
static constexpr const char * type = "value"; | |
}; | |
template <typename T> | |
struct ShowType<T&> | |
{ | |
static constexpr const char * type = "lvalue ref"; | |
}; | |
template <typename T> | |
struct ShowType<T&&> | |
{ | |
static constexpr const char * type = "rvalue ref"; | |
}; | |
using namespace std; | |
template <typename T> | |
void showType(T v) | |
{ | |
cout << ShowType<decltype(v)>::type << endl; | |
} | |
int main(int argc, const char *argv[]) | |
{ | |
int v = 0; | |
int &r = v; | |
showType(v); | |
showType(r); | |
showType(std::move(v)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment