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-深浅拷贝
    Python-生成式
    Python-手写web应用
    Python-为什么产生了GIL锁?
    Python-文件处理
    Python-线程
    10大网站设计错误 足以毁掉你的网站【转】
    [转]ASP.NET验证发生前无法调用 Page.IsValid。应在 CausesValidation=True 且已启动回发的控件
    jquery操作字符串常用方法总结及工作代码
    C#中的序列化和反序列化是什么、有什么作用、使用方法详解
  • 原文地址:https://www.cnblogs.com/lwch/p/2656712.html
Copyright © 2011-2022 走看看