Class: fcf::NTest::SharedPtrAny
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.1.1
Provides a boolean representation of the pointer's validity.
The operator bool allows the fcf::NTest::SharedPtrAny instance to be used directly in boolean contexts, such as if statements or loops.
It returns true if the instance manages a valid object, and false if the instance is null (i.e., it does not point to any managed resource).
Result
bool
- Returns true if the pointer is non-null, false otherwise.
Example: Boolean Context Usage
Demonstrates how to use the fcf::NTest::SharedPtrAny object in conditional statements to check for nullity.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE("SharedPtrAny", "Demo", "BoolOperatorTest"){
struct Data {
Data() {}
};
// 1. Create a valid pointer
fcf::NTest::SharedPtrAny validPtr = fcf::NTest::SharedPtrAny::make<Data>();
// 2. Create a null pointer
fcf::NTest::SharedPtrAny nullPtr;
// 3. Test valid pointer in an if-statement
if (!validPtr) {
FCF_TEST(false, "Valid pointer should evaluate to true");
}
// 4. Test null pointer in an if-statement
if (nullPtr) {
FCF_TEST(false, "Null pointer should evaluate to false");
}
// 5. Explicit boolean check
FCF_TEST(static_cast<bool>(validPtr) == true, "Explicit cast should be true");
FCF_TEST(static_cast<bool>(nullPtr) == false, "Explicit cast should be false");
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "SharedPtrAny" -> "Demo" -> "BoolOperatorTest" ...
[SUCCESS] Test completed successfully (0.000`001`001 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`001`001 sec