• c++11 静态断言


    c++11 静态断言

    #define _CRT_SECURE_NO_WARNINGS
    
    #include <iostream>
    #include <string>
    #include <vector>
    #include <map>
    
    
    void mytest()
    {
        bool flag = false;
    
        // 在程序运行阶段进行检测,如果条件为真,程序正常执行,如果为假,终止程序,提示错误
        // 需要包含 assert.h 头文件,实现是一个宏,禁用断言可以使用 #define NDEBUG
        //assert(flag == true);
    
        // C++ 11新增了关键字static_assert,可用于在编译阶段对断言进行测试。
        // 静态断言的好处:
        // 更早的报告错误,我们知道构建是早于运行的,更早的错误报告意味着开发成本的降低
        // 减少运行时开销,静态断言是编译期检测的,减少了运行时开销
        // 语法如下: static_assert(常量表达式,提示字符串)
        // 注意:只能是常量表达式,不能是变量
    
        //该static_assert用来确保编译仅在32位的平台上进行,不支持64位的平台
        static_assert(sizeof(void *) == 4, "64-bit code generation is not supported."); 
    
        return;
    }
    
    int main()
    {
        mytest();
    
        system("pause");
        return 0;
    }
  • 相关阅读:
    LRU Algorithm Gym
    Running Routes Kattis
    Box HDU
    manjaro 安装 tim 后无法输入中文
    Angle Beats Gym
    Fish eating fruit 沈阳网络赛(树形dp)
    请求接口模板
    Droppable 拖拽实例
    线程处理
    网站的配置文件XML读写
  • 原文地址:https://www.cnblogs.com/lsgxeva/p/7787283.html
Copyright © 2020-2023  润新知