C ++ really allows this, but I would not do it if I were you.
Not everything that C ++ allows is a good idea. A good programmer should consider two things: readability and performance. A blogger (I donβt remember who) once said that a programmer does not program computers, they should program for programmers.
This means that you should try to make it as easy as possible. Condensation of several lines into one actually reduces readability, because the reader must stop and think about several things, they need to analyze the concise statement, and not just read it.
What you want to do can also hide errors created by typos. Say for example you typed
function(val == 2)
by mistake. The compiler would also allow this, since it will convert bool to int. Another reader will also not understand this error if he / she does not know the parameter list.
If you are interested in tips and tricks and good programming tips, I highly recommend Code Complete 2 . I have had a book for many years and am still learning new things to improve my code.
source share