ac-library icon indicating copy to clipboard operation
ac-library copied to clipboard

Add operator bool to modint

Open szdytom opened this issue 2 years ago • 4 comments

It can be useful if you want something like:

mint x;
// ...
if (x)
  do_sth(x);

szdytom avatar Aug 14 '23 04:08 szdytom

https://github.com/atcoder/ac-library/pull/169/commits/95a6273bb67a1440dffe06687d62b13e12937abd Strange to convert zero value to true.

For conversion rules between bool and int types in the C++ language,

https://timsong-cpp.github.io/cppwp/n4659/conv.prom#6

A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one.

https://timsong-cpp.github.io/cppwp/n4659/conv.bool#1

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true. For direct-initialization, a prvalue of type std​::​nullptr_­t can be converted to a prvalue of type bool; the resulting value is false.

mizar avatar Aug 16 '23 11:08 mizar