A min= idiom in C++?

后端 未结 7 810
旧巷少年郎
旧巷少年郎 2021-02-09 22:10

We use

x += y

instead of

x = x + y

And similarly for *,/,- and other operators. Well, what about

7条回答
  •  生来不讨喜
    2021-02-09 22:45

    C++ has a limited set of operators and keywords.

    What you are trying to do is outside the C++ specification and is not possible.

    You can do the comparison and assignment with this one-liner if you want:

    x = (x < y) ? x : y;

提交回复
热议问题