作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
给定以下代码:
constexpr int omg() { return 42; }
const int a = omg(); // NOT guaranteed to be evaluated at compile time
constexpr const int a = omg(); // guaranteed to be evaluated at compile time
有没有办法强制在编译时评估某些东西而不将其分配给某些 constexpr(或在编译时上下文中,如模板参数或枚举恶作剧)?
像这样:
const int a = force_compute_at_compile_time(omg());
也许是这样的(它不能编译——我对 constexpr 还不是很了解):
template<typename T> constexpr T force_compute_at_compile_time(constexpr const T& a) { return a; }
我是一名优秀的程序员,十分优秀!