Проверьте, является ли выражение xvalue или prvalue

Я просто хочу проверить некоторые правила, описанные в cppreference. Легко проверить, является ли выражение lvalue или rvalue.

#include <cassert>
#include <iostream>

template <typename T>
bool IsLValue(const char* i_expression, T&, bool i_expected = true)
  {
  assert(i_expected);
  std::cout << "l_value : " << i_expression << std::endl;
  return true;
  }

template <typename T>
bool IsLValue(const char* i_expression, T&&, bool i_expected = false)
  {
  assert(!i_expected);
  std::cout << "r_value : " << i_expression << std::endl;
  return false;
  }

int main()
  {
  int i = 10;
  int* p = &i;

  IsLValue("The name of a variable 'i'", i);
  IsLValue("The name of a variable 'p'", p);
  IsLValue("The name of a function 'main' in scope", main);
  IsLValue("The name of a function 'std::cout' in scope", std::cout);
  IsLValue("Built-in pre-increment '++i'", ++i);
  //etc
  return 0;
  }

Есть ли способ проверить, является ли выражение xvalue или prvalue?


person Vladislav    schedule 29.07.2015    source источник
comment
См. этот ответ   -  person Shafik Yaghmour    schedule 29.07.2015
comment
Спасибо. Не понимаю, как я это пропустил.   -  person Vladislav    schedule 29.07.2015