Why does std::basic_ios overload the unary logical negation operator?

前端 未结 3 1857
耶瑟儿~
耶瑟儿~ 2020-12-17 21:02

The C++ IO streams\' base class std::basic_ios defines operator void*() to return !fail() and operator!() to return

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 21:21

    Ok, coming up dry here, I went and asked on comp.lang.c++.moderated.

    At first, the results were just as bad as they've been here, but in the end Daniel Krügler's answer concurred in my suspicion that there are no technical reasons for operator!():

    I have been told, that this additional declaration was added to emphasize the symmetry between the "true" case and it's negation, just as a guide for the reader, nothing more. To be fair, the idiom

    operator void*
    

    was rather new at this time and given this the deduction which syntax support is provided by this feature is not immediately obvious. Other than that there was no further technical reason to do so. [...]

提交回复
热议问题