C + + Type extraction (template type application)

Source: Internet
Author: User

Type extraction #pragma once#include<iostream>using namespace std;struct __truetype//define class normal type (base type) {bool Get () {return true;}}; struct __falsetype//defines class non-basic type {bool Get () {return false;}}; Template <class _tp>//Templates class (type extraction) struct typetraits//non-basic type {typedef __falsetype __ispodtype;}; When you rename a base type class to a non-basic type Class (typedef) to the same name//call __ispodtype.get (), the compiler calls//__falsetype or Typetraits<class t> T's actual type. Truetype get () function to get different bool values
struct typetraits< bool>  //the following are common basic types of special {typedef __truetype      __IsPODType;}; template <>struct typetraits< char>{typedef __truetype      __IsPODType;}; Template <>struct typetraits< unsigned char >{typedef __truetype      __IsPODType;}; template <>struct typetraits< short>{typedef __truetype      __IsPODType;}; Template <>struct typetraits< unsigned short >{typedef __truetype      __IsPODType;}; template <>struct typetraits< int>{typedef __truetype      __IsPODType;}; Template <>struct typetraits< unsigned int >{typedef __truetype      __IsPODType;}; Template <>struct typetraits< long>{typedef __truetype     __ispodtype;}; Template <>struct typetraits< unsigned long >{typedef __truetype      __IsPODType;}; template <>struct typetraits< long long >{typedef __truetype      __IsPODType;}; Template <>struct typetraits< unsigned long long>{typedef __truetype      __IsPODType;}; template <>struct typetraits< float>{typedef __truetype      __IsPODType;}; template <>struct typetraits< double>{typedef __truetype      __IsPODType;}; template <>struct typetraits< long double >{typedef __truetype      __IsPODType;}; Template <class _tp>struct typetraits< _tp*>{typedef __truetype     __ispodtype;}; 


C + + Type extraction (template type application)

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.