問(wèn)題描述
不幸的是,我的庫(kù)的原始版本中遺留了幾個(gè)宏,它們使用了一些非常瘋狂的 C.特別是,我有一系列宏希望將某些類型傳遞給它們.是否可以按照以下方式進(jìn)行操作:
I unfortunately have several macros left over from the original version of my library that employed some pretty crazy C. In particular, I have a series of macros that expect certain types to be passed to them. Is it possible to do something along the lines of:
static_assert(decltype(retval) == bool);
怎么辦?有什么聰明的選擇嗎?
是的,我知道宏很糟糕.我知道 C++ 不是 C,等等.
Yes I'm aware macros are bad. I'm aware C++ is not C, etc.
這是一些相關(guān)代碼,以及源文件.歡迎提出建議.原始問(wèn)題保持不變.
Here is some related code, and the source file. Suggestions are welcome. The original question remains the same.
推薦答案
我發(fā)現(xiàn)這是最干凈的,使用@UncleBens 建議:
I found this to be the cleanest, using @UncleBens suggestion:
#include <type_traits>
static_assert(std::is_same<decltype(retval), bool>::value, "retval must be bool");
這篇關(guān)于使用 static_assert 檢查傳遞給宏的類型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!