example4_constant_expression_usage.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <type_traits>

template<typename T, typename U>
constexpr bool are_same_types() {
    return std::is_same<T, U>::value;
}

int main() {
    constexpr bool result1 = are_same_types<int, int>();
    constexpr bool result2 = are_same_types<int, double>();

    static_assert(result1, "int and int should be the same type");
    static_assert(!result2, "int and double should not be the same type");

    std::cout << "All static assertions passed!" << std::endl;

    return 0;
}
Back to std_is_same