1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| // g++ -Wall -Wextra -Wconversion -Wsign-conversion -std=c++11 -pedantic -fopenmp main.cpp -o main && ./main
#include <iostream>
#include <type_traits>
#include <limits>
template <class T>
class int_or_uint
{
static_assert(std::is_same<T, int>::value || std::is_same<T, unsigned int>::value, "int_or_uint<T>: error: T is not int or unsigned int");
};
template <class T>
class any_integer
{
static_assert(std::numeric_limits<T>::is_integer, "any_integer<T>: error: T is not an integer");
};
int main ()
{
int_or_uint<int> a;
int_or_uint<unsigned int> b;
//int_or_uint<float> c; // error: static assertion failed: int_or_uint<T>: error: T is not int or unsigned int
any_integer<long int> d;
any_integer<char> e;
//any_integer<double> f; // error: static assertion failed: any_integer<T>: error: T is not an integer
return 0;
} |