specifiers() method from fcf::Type class
Class:
Package: fcfBasis
File: bits/PartType/TypeDefinition.hpp
Available from version: 1.0.1
Retrieves the map of registered specifiers for the given type.
The method returns a constant reference to a map where the key is the specifier's type index and the value is a
This is useful for inspecting at runtime which operations are supported by a type or for performing dynamic dispatch using universal calls.
Result
- A constant reference to the map of registered specifiers.
Example: Inspecting supported specifiers
#include <iostream>
#include <string>
// Define an implementation macro to include the implementation section in header files
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
// 1. Define a custom structure for demonstration
struct MyCustomStruct {
int id;
std::string name;
};
// 2. Register the type in the fcf system
FCF_TYPE_REGISTRATION (MyCustomStruct, "MyCustomStruct", 0);
// 3. Implement a specifier (e.g., LessSpecifier)
namespace fcf {
template<> struct Type<MyCustomStruct, LessSpecifier > : public TypeImpl<MyCustomStruct, LessSpecifier > {
inline bool operator()(const MyCustomStruct* a_left, const MyCustomStruct* a_right) {
return a_left->id < a_right->id;
}
};
}
// 4. Bind the specifier to the type
FCF_SPECIFIER_REGISTRATION (MyCustomStruct, fcf::LessSpecifier );
int main() {
// 5. Access the type descriptor
fcf::Type <MyCustomStruct> typeDescriptor;
// 6. Retrieve the map of specifiers
const fcf::TypeInfo::SpecifiersType & specMap = typeDescriptor.specifiers () ;
std::cout << "=== Supported Specifiers ===" << std::endl;
std::cout << "Number of registered specifiers: " << specMap.size() << std::endl;
// 7. Check if a specific specifier is registered
// We use the index of LessSpecifier to look it up in the map
unsigned int lessIndex = fcf::Type <fcf::LessSpecifier >().index ();
if (specMap.count(lessIndex)) {
std::cout << "[OK] LessSpecifier is supported for MyCustomStruct." << std::endl;
} else {
std::cout << "[ERROR] LessSpecifier is NOT supported." << std::endl;
}
return 0;
}
Output:
=== Supported Specifiers ===
Number of registered specifiers: 1
[OK] LessSpecifier is supported for MyCustomStruct.
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.