Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

*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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading