How do I check the type of a variable

I am making a simple calculator, but I want to check the type of a variable, to see if it's an integer or a double, is there any way to do this?
The type of a variable is determined during compilation of the program. There is such template structure in C++ as std::is_same, declared in header <type_traits>, that can be used. But it seems that you need to determine the type of an expression value not the type of some variable.
vlad from moscow wrote:
The type of a variable is determined during compilation of the program. There is such template structure in C++ as std::is_same, declared in header <type_traits>, that can be used. But it seems that you need to determine the type of an expression value not the type of some variable.
Yes, thanks I actually need to check the type for an expression value, not a variable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <type_traits>

int main()
{
    int i = 0 ;
    double d = 7.6 ;

    auto a = i + 7L - d ;

    std::cout << std::is_integral< decltype(a) >::value << '\n' ; 
    std::cout << std::is_integral< decltype( i * 22 ) >::value << '\n' ;
    std::cout << std::is_floating_point< decltype( i * d ) >::value << '\n' ;
}
Topic archived. No new replies allowed.