How to determine the largest number of three numbers using C ++?
I need to simplify this
w=(z>((x>y)?x:y)?z:((x>y)?x:y));
Conditional expressions do not simplify this.
Starting with C ++ 11, you can do
w = std::max({ x, y, z });
w = std::max(std::max(x, y), z);
- one of the methods.
big = a > b? (a > c? a: c): (b > c? b: c);
if
int w = x; if(y > w) w = y; if(z > w) w = z;
w .
w
oisyn answer ( ) Bathesheba ( ) std::ref , std::max:
std::ref
std::max
using std::ref; w = std::max({ref(x), ref(y), ref(z)});
This is only beneficial if link creation is cheaper than copying (and this is not for type primitives int)
int
Source: https://habr.com/ru/post/1689626/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1689621/moving-nodejs-to-a-docker-container-receiving-a-cannot-file-module-error&usg=ALkJrhhcYU1PMDLfuDJaJIpB8OobPzMDvAЕсть ли способ использования DebugFormat() с аргументами, которые дорого строить? - c#How to read trace in R - functionC #: how to avoid this potential memory leak - garbage-collectionpre-fill stdin in c - cThe Constant property cannot be initialized in the convenience initializer of a derived class - initializationThe difference between Conv2D and Convolution2D in Keras - machine-learningElixir / Erlang: How to find the source of high CPU usage? - erlangwhy notifyItemRemoved (getAdapterPosition ()); does not work - androidMany build errors after updating pod - iosAll Articles