> Somebody with basic understanding of math should expect
>
1 2
|
int x =0;
> return (-1 < x < 1);
|
> to return true or disallow its use
Anybody with basic understanding of programming would know that the
int
is not the integer in mathematics; for instance that can't hold any integer. That if
x
and
y
are two integers, while
x+y
is always well defined in mathematics, it is not so in programming.
Anybody with a basic understanding of C++ would realize that the
<
is a binary operator which results in a bool, that associativity is involved, that
(int)(-1 < x < 1)
would give the same results in both C and C++.
> I haven't seen any use of implicit bool→int conversion .... Talk about self descripting code.
Then you have seen very little code. Mny calls from within C++ to a C function taking a boolean value would involve an implicit conversion from
bool
to
int
.
char c = ... ; if( std::isupper(c) ) { /* ... */ }
involves implicit conversions from
char
to
int
, and from
int
to
bool
People who believe that to be self-describing, the code must be written as :
if( static_cast<bool>( std::isupper( static_cast<int>(c) ) ) { /* ... */ }
have my sympathies.
> C++ bool type and C bool typedef is not compatible ... blah blah
That is asinine. C compatibility does not mean that C++ code can be picked up and compiled with a C compiler.
It just means that
1 2 3 4 5 6 7
|
std::mutex make_win32_mutex( /* ... */ bool own = false, bool allow_inheritance = false )
{
// ...
::SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), nullptr, allow_inheritance } ;
auto m = ::CreateMutex( *sa, own, nullptr ) ;
// ...
}
|
will work seamlessly. Not that this function can be compiled with a C compiler. But that one does not have to write (using some absurd notion of self-describing code)
1 2 3 4 5 6 7 8 9
|
std::mutex make_win32_mutex( /* ... */ bool own = false, bool allow_inheritance = false )
{
// ...
::SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), static_cast<void*>(nullptr),
static_cast<int>(allow_inheritance) } ;
auto m = ::CreateMutex( &sa, static_cast<int>(own),
static_cast<void*>(nullptr) ) ;
// ...
}:
|