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

specifiers() method from fcf::Type class

const fcf::TypeInfo::SpecifiersType& specifiers()

Class: fcf::Type

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 fcf::SpecifierInfo object. This map contains all the runtime behaviors (like comparison, addition, or container access) that have been bound to this specific type via FCF_SPECIFIER_REGISTRATION or FCF_SPECIFIER_REGISTRATION_FORCE.

This is useful for inspecting at runtime which operations are supported by a type or for performing dynamic dispatch using universal calls.

Result
const fcf::TypeInfo::SpecifiersType&
- 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.