Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- struct value_category {
- // Or can be an integral or enum value
- static constexpr auto value = "prvalue";
- };
- template<typename T>
- struct value_category<T&> {
- static constexpr auto value = "lvalue";
- };
- template<typename T>
- struct value_category<T&&> {
- static constexpr auto value = "xvalue";
- };
- // Double parens for ensuring we inspect an expression,
- // not an entity
- #define VALUE_CATEGORY(expr) value_category<decltype((expr))>::value
- int main() {
- int x;
- cout << VALUE_CATEGORY(x) << endl; // prints lvalue
- cout << VALUE_CATEGORY(move(x)) << endl; // prints xvalue
- cout << VALUE_CATEGORY(42) << endl; // prints prvalue
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement