117 lines
3.4 KiB
C++
117 lines
3.4 KiB
C++
#ifndef IS_INTEGRAL_HPP
|
|
# define IS_INTEGRAL_HPP
|
|
|
|
namespace ft {
|
|
|
|
//struct true_type {
|
|
// typedef bool value_type;
|
|
// typedef true_type type;
|
|
// static const bool value = true;
|
|
//};
|
|
//
|
|
//struct false_type {
|
|
// typedef T value_type;
|
|
// typedef false_type type;
|
|
// static const bool value = false;
|
|
//};
|
|
|
|
template <class T> struct is_integral
|
|
{
|
|
typedef char yes[1];
|
|
typedef yes no[2];
|
|
|
|
static T type;
|
|
|
|
// integral types : https://www.cplusplus.com/reference/type_traits/is_integral/
|
|
static yes& test(bool);
|
|
static yes& test(char);
|
|
// static yes& test(char16_t);
|
|
// static yes& test(char32_t);
|
|
static yes& test(wchar_t);
|
|
static yes& test(signed char);
|
|
static yes& test(short int);
|
|
static yes& test(int);
|
|
static yes& test(long int);
|
|
static yes& test(long long int);
|
|
static yes& test(unsigned char);
|
|
static yes& test(unsigned short int);
|
|
static yes& test(unsigned int);
|
|
static yes& test(unsigned long int);
|
|
static yes& test(unsigned long long int);
|
|
|
|
/*
|
|
static yes& test(const bool);
|
|
static yes& test(const char);
|
|
static yes& test(const wchar_t);
|
|
static yes& test(const signed char);
|
|
static yes& test(const short int);
|
|
static yes& test(const int);
|
|
static yes& test(const long int);
|
|
static yes& test(const long long int);
|
|
static yes& test(const unsigned char);
|
|
static yes& test(const unsigned short int);
|
|
static yes& test(const unsigned int);
|
|
static yes& test(const unsigned long int);
|
|
static yes& test(const unsigned long long int);
|
|
|
|
static yes& test(volatile bool);
|
|
static yes& test(volatile char);
|
|
static yes& test(volatile wchar_t);
|
|
static yes& test(volatile signed char);
|
|
static yes& test(volatile short int);
|
|
static yes& test(volatile int);
|
|
static yes& test(volatile long int);
|
|
static yes& test(volatile long long int);
|
|
static yes& test(volatile unsigned char);
|
|
static yes& test(volatile unsigned short int);
|
|
static yes& test(volatile unsigned int);
|
|
static yes& test(volatile unsigned long int);
|
|
static yes& test(volatile unsigned long long int);
|
|
|
|
static yes& test(const volatile bool);
|
|
static yes& test(const volatile char);
|
|
static yes& test(const volatile wchar_t);
|
|
static yes& test(const volatile signed char);
|
|
static yes& test(const volatile short int);
|
|
static yes& test(const volatile int);
|
|
static yes& test(const volatile long int);
|
|
static yes& test(const volatile long long int);
|
|
static yes& test(const volatile unsigned char);
|
|
static yes& test(const volatile unsigned short int);
|
|
static yes& test(const volatile unsigned int);
|
|
static yes& test(const volatile unsigned long int);
|
|
static yes& test(const volatile unsigned long long int);
|
|
*/
|
|
|
|
|
|
// non-template function with direct matching are always considered first
|
|
// then the function template with direct matching are considered
|
|
// https://stackoverflow.com/questions/12877546/how-do-i-avoid-implicit-conversions-on
|
|
template <class C> static no& test(C);
|
|
|
|
static const bool value = sizeof(test(type)) == sizeof(yes);
|
|
};
|
|
|
|
} // namespace ft
|
|
|
|
// "template <>" introduce a total specialization of a template :
|
|
//
|
|
// template <typename T>
|
|
// class A
|
|
// {
|
|
// // body for the general case
|
|
// };
|
|
//
|
|
// template <>
|
|
// class A<bool>
|
|
// {
|
|
// // body that only applies for T = bool
|
|
// };
|
|
//
|
|
// https://stackoverflow.com/questions/6288812/what-is-the-meaning-of-template-with-empty-angle-brackets-in-c
|
|
|
|
// SFINAE : https://jguegant.github.io/blogs/tech/sfinae-introduction.html
|
|
|
|
#endif
|
|
|