# Include <iostream>
Using namespace STD;
// Some small applications used for template training identify basic and custom types
// The method of use is to give a limited basic type, no other
// Basic class template enumeration non-basic type
Template <typename T>
Class isfoundationtype
{
Public:
Enum {Yes = 0, NO = 1 };
};
// Macro-defined macro_foundation_type (t) Specialization calls all
// The basic data type enumeration is yes = 1
# Define macro_foundation_type (T )/
Template <> class isfoundationtype <t>/
{/
Public :/
Enum {Yes = 1, no = 0 };/
};/
// Use macros for special operations to obtain the most special instance points
Macro_foundation_type (void)
Macro_foundation_type (bool)
Macro_foundation_type (char)
Macro_foundation_type (unsigned char)
Macro_foundation_type (wchar_t)
Macro_foundation_type (short)
Macro_foundation_type (signed INT)
Macro_foundation_type (unsigned INT)
Macro_foundation_type (signed long)
Macro_foundation_type (unsigned long)
# If longlong_exists
Macro_foundation_type (signed long)
Macro_foundation_type (unsigned long)
# Endif
Macro_foundation_type (double)
Macro_foundation_type (float)
Macro_foundation_type (Long Double)
// Test the function template. It is very simple.
// It is still useful, and a limited number of matched examples are supported.
Template <typename T>
Void test (T const & T)
{
If (isfoundationtype <t >:: yes)
{
Cout <"t is fundamental type" <Endl;
}
Else
{
Cout <"t isn' t fundamental type" <Endl;
}
If (isdouble <t >:: yes)
{
Cout <"t is double type" <Endl;
}
Else
{
Cout <"t isn' t double type" <Endl;
}
}