Hi I am learning c++ and I read about type traits such as is_const. is_const can be called in one line like,
cout << is_const<double>::value << endl;
I made my own version of is_const but to test if a variable is const, and it can be used like this,
#include<iostream>
using namespace std;
template<typename T>
struct check_const {
check_const(const T *x): val(std::true_type{})
{ }
check_const(T *x) : val(std::false_type{})
{ }
bool val;
};
int main()
{
const double pi= 3.14;
check_const<double> r(&pi);
cout << r.val << endl; // returns 1
double x= 2.7;
check_const<double> s(&x);
cout << s.val << endl; // returns 0
return(0);
}
I would like to call check_const in one line as well, but the compiler keeps giving me errors like
"typename not allowed"
when I try calling it like
cout << check_const<double> t(&pi)::val << endl;
How can I change check_const, so it can be called in one line?