Search code examples
c++c++17template-meta-programmingc++-templates

Why std::is_integral returns false for decltype(*t) where t is int*?


#include<iostream>
using namespace std;
int main() {
  int* t;
  using T = decltype(*t);
  cout << is_integral<T>::value << endl;
  return 0;
}

Why does the code above print 0?


Solution

  • *t is an lvalue expression, then decltype(*t) leads to a reference type as int&.

    b) if the value category of expression is lvalue, then decltype yields T&;

    You might use std::remove_reference to get the result you expected. E.g.

    is_integral<remove_reference_t<T>>::value
    

    LIVE