is() method from fcf::NTest::SharedPtrAny class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.4
Performs a check for consistency of the stored type.
Template arguments
Result
- 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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.