zoukankan      html  css  js  c++  java
  • 如何比较两个变量的类型是否相同

            template <typename T1, typename T2>
            inline const bool compare_type(T1, T2)
            {
                return false;
            }

            template <>
            inline const bool compare_type(intint)
            {
                return true;
            }

            template <>
            inline const bool compare_type(floatfloat)
            {
                return true;
            }

            template <>
            inline const bool compare_type(doubledouble)
            {
                return true;
            }

            template <>
            inline const bool compare_type(charchar)
            {
                return true;
            }

            template <>
            inline const bool compare_type(wchar_t, wchar_t)
            {
                return true;
            }

            template <typename T1, typename T2>
            inline const bool compare_type(T1*, T2*)
            {
                return compare_type(T1(), T2());
            }

            template <typename T1, typename T2>
            inline const bool compare_type(const T1*, const T2*)
            {
                return compare_type(T1(), T2());
            }

            template <typename T1, typename T2>
            inline const bool compare_type(const T1*, T2*)
            {
                return false;
            }

            template <typename T1, typename T2>
            inline const bool compare_type(T1*, const T2*)
            {
                return false;
            }
    通过特例化,我们可以很轻松的查看两个变量的类型是否相同。
  • 相关阅读:
    python random模块随机取list中的某个值
    初学习-python打印乘法表、正方形、三角形
    python字符串拼接相关
    导航条2-
    HTML输入验证提示信息
    CMD常用功能
    AngularJs学习笔记(4)——自定义指令
    AngularJs学习笔记(3)——scope
    AngularJs学习笔记(2)——ng-include
    AngularJs学习笔记(1)——ng-app
  • 原文地址:https://www.cnblogs.com/lwch/p/2656712.html
Copyright © 2011-2022 走看看