【问题标题】:What does a>?=b mean?a>?=b 是什么意思?
【发布时间】:2013-12-16 18:44:19
【问题描述】:

找到下面的代码,不明白是什么意思:

res>?=m[2];

这是我找到它的代码以及它的一些上下文。

vector<int> m(3);
int s = 0;
... do stuff with m ...
res>?=m[2];
return res;

【问题讨论】:

  • 链接仅供注册用户使用。你能至少显示 res 变量的类型吗?
  • 这肯定已经在某处了。你可能会找到我记得的那个in here。这是一个旧的 GCC 扩展。

标签: c++ operators


【解决方案1】:

这是一个旧的 GCC 扩展。

a &gt;?= b 的等价物是a = max(a,b);

您可以查看Minimum and Maximum Operators in C++

使用返回“最小值”或 两个参数的“最大值”。在 GNU C++(但不是 GNU C)中,

a &lt;? b

是最小值,返回数值a和b中较小的一个;

一个>? b

是最大值,返回数值a和b中较大的一个。

On a side note:-

这些运算符是非标准的,是deprecated in GCC。您应该改用 std::minstd::max

【讨论】:

【解决方案2】:

这当然不是标准的 C++。我可以猜测这是赋值+三元运算符的快捷方式,类似于赋值+二元运算符,如operator+= 等:

 res = (res > m[2]) ? res : m[2];

您可以在此处阅读相关内容:Extensions to the C++ Language

a <? b
is the minimum, returning the smaller of the numeric values a and b;
a >? b
is the maximum, returning the larger of the numeric values a and b.

【讨论】:

    猜你喜欢
    • 2017-02-02
    • 2014-02-09
    • 2012-06-14
    • 2018-08-06
    • 1970-01-01
    • 2022-11-10
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多