FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

is() method from fcf::NTest::SharedPtrAny class

template <typename Ty>
bool is() const

Class: fcf::NTest::SharedPtrAny

Package: fcfTest

File: test.hpp

Available from version: 1.2.4

Performs a check for consistency of the stored type.

Template arguments
Ty - The type with which the stored type is compared
Result
bool
- Returns true if Ty matches the stored type.

Example:

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DEFINE("SharedPtrAny", "Demo", "CastExample"){ struct TargetType { std::string data; TargetType(std::string d) : data(d) {} }; // Create a SharedPtrAny holding a TargetType object fcf::NTest::SharedPtrAny ptr = fcf::NTest::SharedPtrAny::make<TargetType>("Success"); // Safe usage pattern if (ptr.is<TargetType>()) { TargetType* safePtr = ptr.cast<TargetType>(); fcf::NTest::log() << "Retrieved data: " << safePtr->data << std::endl; } } 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" -> "CastExample" ... > Retrieved data: Success [SUCCESS] Test completed successfully (0.000`005`120 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`005`120 sec