How to build a custom macro that behaves differently when used as constexpr (like assert)?

旧城冷巷雨未停 提交于 2019-12-11 06:19:12

问题


Starting in C++14, the assert macro can be used in functions even when they are defined as constexpr. I know this has to do with the fact that it evaluates to "true", but I'm having trouble figuring out what the actual code looks like.

Specifically, how do you build a macro that prints something when run in a constexpr function that is being evaluated at run time, but shuts this non-constexpr behavior off when in a constexpr function that is being evaluated at compile time.

来源:https://stackoverflow.com/questions/47725266/how-to-build-a-custom-macro-that-behaves-differently-when-used-as-constexpr-lik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!