auto_handle::operator bool
Operator for using auto_handle in a conditional expression.
operator bool();
Return Value
true if the wrapped object is valid; false otherwise.
Remarks
This operator actually converts to _detail_class::_safe_bool which is safer than bool because it cannot be converted to an integral type.
Example
// msl_auto_handle_operator_bool.cpp
// compile with: /clr
#include <msclr\auto_handle.h>
using namespace System;
using namespace msclr;
int main() {
auto_handle<String> s1;
auto_handle<String> s2 = "hi";
if ( s1 ) Console::WriteLine( "s1 is valid" );
if ( !s1 ) Console::WriteLine( "s1 is invalid" );
if ( s2 ) Console::WriteLine( "s2 is valid" );
if ( !s2 ) Console::WriteLine( "s2 is invalid" );
s2.reset();
if ( s2 ) Console::WriteLine( "s2 is now valid" );
if ( !s2 ) Console::WriteLine( "s2 is now invalid" );
}
s1 is invalid
s2 is valid
s2 is now invalid
Requirements
Header file <msclr\auto_handle.h>
Namespace msclr