A min= idiom in C++?

后端 未结 7 818
旧巷少年郎
旧巷少年郎 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 23:03

    The options you have:

    x = std::min(x,y)
    

    or

    x = y < x ? y : x;
    

    or

    if (y < x) x = y;
    
    0 讨论(0)
提交回复
热议问题