什么>?= b是什么意思?

ale*_*027 29 c++ operators

我找到了下面的代码,不明白它的含义:

res>?=m[2];
Run Code Online (Sandbox Code Playgroud)

这是我找到它的代码和它的一些上下文.

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

Rah*_*thi 37

这是旧的GCC扩展.

相当于a >?= bISa = max(a,b);

您可以在C++中查看最小和最大运算符

让运算符返回两个参数的"最小值"或"最大值"非常方便.在GNU C++中(但不是在GNU C中),

a <? b

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

a>?b

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

在旁注: -

这些运算符是非标准运算符,在GCC已弃用.你应该使用std :: minstd :: max.

  • 请注意,它已被弃用:http://gcc.gnu.org/onlinedocs/gcc/Deprecated-Features.html (6认同)

klm*_*123 7

这肯定不是标准的C++.我可以猜测这是赋值+三元运算符的快捷方式,simmilary是赋值+二元运算符,比如operator+=和其他运算符:

 res = (res > m[2]) ? res : m[2];
Run Code Online (Sandbox Code Playgroud)

您可以在这里阅读相关内容:C++语言的扩展:

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.
Run Code Online (Sandbox Code Playgroud)