9 Star 31 Fork 22

10km/common_source_cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
assert_macros.h 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
/*
* assert_utilits.h
*
* Created on: 2016年2月3日
* Author: 10km
*/
#ifndef COMMON_SOURCE_CPP_ASSERT_MACROS_H_
#define COMMON_SOURCE_CPP_ASSERT_MACROS_H_
#include <stdexcept>
#include <string>
#define _DEF_STRING(x) #x
#define DEF_TO_STRING(x) _DEF_STRING(x)
#define SOURCE_AT __FILE__ ":" DEF_TO_STRING(__LINE__)
#define ERROR_STR(msg) std::string(SOURCE_AT ":").append(msg)
#define throw_except_if_false(except,expression) \
if(!expression)\
throw except();
#define throw_except_if_msg(except,expression,msg) \
if(expression)\
throw except(ERROR_STR(msg));
#define throw_except_if(except,expression) throw_except_if_msg(except,expression,#expression)
#define throw_if_msg(expression,msg) throw_except_if_msg(std::invalid_argument,expression,msg)
#define throw_if(expression) throw_except_if(std::invalid_argument,expression)
#define throw_except_if_null(except,p) throw_except_if_msg(except,nullptr==p,#p" is null")
#define throw_if_null(p) throw_if_msg(nullptr==p,#p" is null")
#endif /* COMMON_SOURCE_CPP_ASSERT_MACROS_H_ */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/l0km/common_source_cpp.git
git@gitee.com:l0km/common_source_cpp.git
l0km
common_source_cpp
common_source_cpp
master

搜索帮助