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

index() method from fcf::Type class

unsigned int index()

Class: fcf::Type

Package: fcfBasis

File: bits/PartType/TypeDefinition.hpp

Available from version: 1.0.1

Retrieves the unique runtime index of the type.

The returned index is a unique identifier for the type within the fcf type system. It can be used for runtime type identification, type matching, and as a key in various type-related registries.

Result
unsigned int
- The unique runtime index of the type.

Example: Getting the type index

#include <iostream> #include <string> // Define an implementation macro to include the implementation section in header files #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> // Custom data type for demonstration struct MyCustomType { int id; }; // Registering the custom type in the fcf system. // This is required so that fcf::Type<MyCustomType> can access its metadata. FCF_TYPE_REGISTRATION(MyCustomType, "MyCustomType", 0); int main() { // 1. Accessing metadata for a built-in pointer type // We use fcf::Type<T> to get a description for std::string* std::cout << "=== [1] Built-in Pointer Type ===" << std::endl; std::cout << "Type index: 0x" << std::hex << fcf::Type<std::string*>().index() << std::dec << std::endl; std::cout << "Type name: " << fcf::Type<std::string*>().name() << std::endl; // 2. Accessing metadata for a custom registered type std::cout << "=== [2] Custom Registered Type ===" << std::endl; // We get the unique runtime index for our custom type std::cout << "Type index: 0x" << std::hex << fcf::Type<MyCustomType>().index() << std::dec << std::endl; std::cout << "Type name: " << fcf::Type<MyCustomType>().name() << std::endl; return 0; }

Output:

=== [1] Built-in Pointer Type === Type index: 0x1000001e Type name: std::string* === [2] Custom Registered Type === Type index: 0x1000015 Type name: MyCustomType