Skip to content

Instantly share code, notes, and snippets.

@beyondwdq
Last active August 29, 2015 14:25
Show Gist options
  • Save beyondwdq/47a7224fe54d257dac47 to your computer and use it in GitHub Desktop.
Save beyondwdq/47a7224fe54d257dac47 to your computer and use it in GitHub Desktop.
#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