- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 Nicolai M. Josuttis 的“The Cpp standard library”一书中,第 2 版中说(5.4,p.125)struct common 类型的定义如下:
template <typename T1, typename T2>
struct common_type<T1,T2> {
typedef decltype(true ? declval<T1>() : declval<T2>()) type;
};
我很难相信这是 common_type 的正确定义。原因:
typedef decltype(true ? declval<T1>() : declval<T2>()) type;//As far as I understand this will always pick second operand, declval<T1>(), due to the fact that there is 'true' value. Am I right?
最佳答案
都是关于条件运算符的。 它不是选择语句,如 if 或 switch。
ISO C++11标准5.16段:
Otherwise, if the second and third operand have different types and either has (possibly cv-qualified) class type, or if both are glvalues of the same value category and the same type except for cv-qualification, an attempt is made to convert each of those operands to the type of the other.
因此,decltype 包含 true 条件并不重要,编译器必须选择普通类型作为结果。
UPD: 5.16 包含对正确行为的进一步描述,您应该查看它以完全理解整个过程。但是对于您的特定问题:
Using this process, it is determined whether the second operand can be converted to match the third operand, and whether the third operand can be converted to match the second operand. If both can be converted, or one can be converted but the conversion is ambiguous, the program is ill-formed. If neither can be converted, the operands are left unchanged and further checking is performed as described below. If exactly one conversion is possible, that conversion is applied to the chosen operand and the converted operand is used in place of the original operand for the remainder of this section.
关于c++ - common_type 的可疑定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13269792/
继this q about GADTs之后,我正在尝试构建一个 EDSL(对于本文中的示例),但没有 GADT。我已经找到了一些可以避免 AST 数据类型加倍的方法;但相反,它似乎将代码加倍。所以我尝
我正在使用 compose 实现 MVI。为了让我遵循正确的事件循环,我需要通过我的 View 模型传播点击事件,然后观察副作用。我看过一些实现,它们都使用 LaunchedEffect(true)
有没有办法使用Python对日志文件中的“可疑时间”进行有效的二进制搜索? 我有一个日志文件,其条目如下: 02:38:18 0 RcvTxData - 11 : Telegram receive
一些黑客可以访问我的数据库,我将找出漏洞;我无权访问服务器日志。我制作了这段代码来保存文本文件中的可疑查询: function query($query) { $file = 'sqllog.txt'
问题背景: 日常对Sql Server 2005关系数据库进行操作时,有时对数据库(如:Sharepoint网站配置数据库名Sharepoint_Config)进行些不正常操作如数据库在读写时而无
1、出错情况 有些时候当你重启了数据库服务,会发现有些数据库变成了正在恢复、置疑、可疑等情况,这个时候DBA就会很紧张了,下面是一些在实践中得到证明的方法。 在一次重启数据
我在尝试解决这段短代码中的运行时段错误时遇到了麻烦。我怀疑这与代码中使用 system() 和 strcpy() 有关,但由于我没有遇到此类错误的经验,所以我不确定该怎么做,而且到目前为止我还没有找到
我正在尝试按照 NutchTutorial 运行基本爬网: bin/nutch crawl urls -dir crawl -depth 3 -topN 5 所以我已经安装了 Nutch,并使用 So
我注意到,当我通过浏览器打开 CSS 时,我看到我所有的图像都预先设置了一些 IP。它看起来像这样: url(http://64.19.142.11/www.mydomain.com/i/pgBg.p
我是一名优秀的程序员,十分优秀!