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

size() method from fcf::Type class

size_t size()

Class: fcf::Type

Package: fcfBasis

File: bits/PartType/TypeDefinition.hpp

Available from version: 1.0.1

Returns the size of the type in bytes.

This method returns the size of the type in bytes, as it is stored in memory.

For reference types, the size returned is the size of a pointer.

Result
size_t
- The size of the type in bytes.

Example: Basic usage of Type::size

#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; double value; char buffer[16]; }; // 2. Register the type in the fcf system FCF_TYPE_REGISTRATION(MyCustomStruct, "MyCustomStruct", 0); int main() { // 3. Access metadata for the custom type fcf::Type<MyCustomStruct> customType; // 4. Retrieve the size using the size() method // The customType.size() method returns the size in bytes std::cout << "Custom type size: " << customType.size() << " bytes" << std::endl; // 5. Accessing metadata for a built-in type (e.g., int) fcf::Type<int> intType; std::cout << "Built-in int size: " << intType.size() << " bytes" << std::endl; // 6. Accessing metadata for a pointer type (should return size of a pointer) fcf::Type<std::string*> ptrType; std::cout << "Pointer type size: " << ptrType.size() << " bytes" << std::endl; return 0; }

Output:

Custom type size: 32 bytes Built-in int size: 4 bytes Pointer type size: 8 bytes