aled1027
aled1027

Reputation: 1356

What does a>?=b mean?

I found the below code and don't understand what it means:

res>?=m[2];

Here's the code to where I found it and some context for it.

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

Upvotes: 30

Views: 2984

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

It is an old GCC extension.

The equivalent of a >?= b is a = max(a,b);

You may check out Minimum and Maximum Operators in C++

It is very convenient to have operators which return the "minimum" or the "maximum" of two arguments. In GNU C++ (but not in GNU 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.

On a side note:-

These operators are non-standard and are deprecated in GCC. You should use std::min and std::max instead.

Upvotes: 38

klm123
klm123

Reputation: 12865

This is certainly not standard C++. I can guess that is shortcut for the assignment + ternary operator, simmilary to assignment + binary operators, like operator+= and others:

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

You can read related here: 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.

Upvotes: 7

Related Questions