Use STL to differentiate applications

Source: Internet
Author: User

# 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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.