⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assert.h

📁 Full support for extended regular expressions (those with intersection and complement); Support for
💻 H
字号:

// a C++ exception-throwing <assert.h> replacement.

#ifndef __DOLPHIN__ASSERT_H

#define __DOLPHIN__ASSERT_H

#undef _ASSERT_H
#define _ASSERT_H		// to prevent standard assert.h inclusion

#define __DOLPHIN__ASSERT_H__ATTEMPT_TO_PLEASE_THE_COMPILER // see below

#include <iostream>

class FailedAssertion
{
public:
	int line;
	char *fn;
	char *condition;
	
	FailedAssertion(int supplied_line, char *supplied_fn, char *supplied_condition)
	{
		line=supplied_line;
		fn=supplied_fn;
		condition=supplied_condition;
	}
};

#undef assert
#ifdef NDEBUG
	#define assert(condition) (condition ? true : false)
#else
	#define assert(condition) ((condition) ? true : assert_proc(__LINE__, __FILE__, #condition))
#endif

inline bool assert_proc(int line, char *fn, char *condition)
{
	// it's better to print it now rather than to rely upon some good man
	// somewhere upward the call stack: it can easily happen that we crash
	// while *** the stack.
	std::cout << "\nAssertion failed: " << condition << ", file " << fn
		<< ", line " << line << ".\n";
	
	throw *new FailedAssertion(line, fn, condition);
	
#ifdef __DOLPHIN__ASSERT_H__ATTEMPT_TO_PLEASE_THE_COMPILER
	return false;
#endif
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -