{"id":13533645,"url":"https://github.com/skypjack/meta","last_synced_at":"2025-04-05T11:08:00.645Z","repository":{"id":71313221,"uuid":"152803601","full_name":"skypjack/meta","owner":"skypjack","description":"Header-only, non-intrusive and macro-free runtime reflection system in C++","archived":false,"fork":false,"pushed_at":"2020-05-21T06:54:38.000Z","size":986,"stargazers_count":623,"open_issues_count":0,"forks_count":51,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-29T10:05:58.965Z","etag":null,"topics":["cpp","cpp-17","entt","header-only","macro-free","meta","modern-cpp","non-instrusive","reflection","runtime","runtime-reflection"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skypjack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"},"funding":{"github":"skypjack","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.paypal.me/skypjack"}},"created_at":"2018-10-12T20:20:40.000Z","updated_at":"2025-03-19T03:35:41.000Z","dependencies_parsed_at":"2023-05-29T14:00:52.589Z","dependency_job_id":null,"html_url":"https://github.com/skypjack/meta","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skypjack%2Fmeta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skypjack%2Fmeta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skypjack%2Fmeta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skypjack%2Fmeta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skypjack","download_url":"https://codeload.github.com/skypjack/meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325693,"owners_count":20920714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp-17","entt","header-only","macro-free","meta","modern-cpp","non-instrusive","reflection","runtime","runtime-reflection"],"created_at":"2024-08-01T07:01:21.747Z","updated_at":"2025-04-05T11:08:00.623Z","avatar_url":"https://github.com/skypjack.png","language":"C++","readme":"# Header-only runtime reflection system in C++\n\n\u003c!--\n@cond TURN_OFF_DOXYGEN\n--\u003e\n[![GitHub version](https://badge.fury.io/gh/skypjack%2Fmeta.svg)](https://github.com/skypjack/meta/releases)\n[![Build Status](https://github.com/skypjack/meta/workflows/build/badge.svg)](https://github.com/skypjack/meta/actions)\n[![Coverage](https://codecov.io/gh/skypjack/meta/branch/master/graph/badge.svg)](https://codecov.io/gh/skypjack/meta)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/skypjack)\n\n\u003e The reflection system was born within [EnTT](https://github.com/skypjack/entt)\n\u003e and is developed and enriched there. This project is designed for those who\n\u003e are interested only in a header-only, full-featured, non-intrusive and macro\n\u003e free reflection system which certainly deserves to be treated also separately\n\u003e due to its quality and its rather peculiar features.\n\nIf you use `meta` and you want to say thanks or support the project, please\n**consider becoming a\n[sponsor](https://github.com/users/skypjack/sponsorship)**.\u003cbr/\u003e\nYou can help me make the difference.\n[Many thanks](https://skypjack.github.io/sponsorship/) to those who supported me\nand still support me today.\n\n# Table of Contents\n\n* [Introduction](#introduction)\n* [Build Instructions](#build-instructions)\n  * [Requirements](#requirements)\n  * [Library](#library)\n  * [Documentation](#documentation)\n  * [Tests](#tests)\n* [Crash course](#crash-course)\n  * [Names and identifiers](#names-and-identifiers)\n  * [Reflection in a nutshell](#reflection-in-a-nutshell)\n  * [Any as in any type](#any-as-in-any-type)\n  * [Enjoy the runtime](#enjoy-the-runtime)\n  * [Policies: the more, the less](#policies-the-more-the-less)\n  * [Named constants and enums](#named-constants-and-enums)\n  * [Properties and meta objects](#properties-and-meta-objects)\n  * [Unregister types](#unregister-types)\n* [Contributors](#contributors)\n* [License](#license)\n* [Support](#support)\n\u003c!--\n@endcond TURN_OFF_DOXYGEN\n--\u003e\n\n# Introduction\n\nReflection (or rather, its lack) is a trending topic in the C++ world. I looked\nfor a third-party library that met my needs on the subject, but I always came\nacross some details that I didn't like: macros, being intrusive, too many\nallocations.\u003cbr/\u003e\nIn one word: **unsatisfactory**.\n\nI finally decided to write a built-in, non-intrusive and macro-free runtime\nreflection system for my own.\u003cbr/\u003e\nMaybe I didn't do better than others or maybe yes. Time will tell me.\n\n# Build Instructions\n\n## Requirements\n\nTo be able to use `meta`, users must provide a full-featured compiler that\nsupports at least C++17.\u003cbr/\u003e\nThe requirements below are mandatory to compile the tests and to extract the\ndocumentation:\n\n* CMake version 3.2 or later.\n* Doxygen version 1.8 or later.\n\nIf you are looking for a C++14 version of `meta`, feel free to\n[contact me](https://github.com/skypjack).\n\n## Library\n\n`meta` is a header-only library. This means that including the `factory.hpp` and\n`meta.hpp` headers is enough to include the library as a whole and use it.\u003cbr/\u003e\nIt's a matter of adding the following lines to the top of a file:\n\n```cpp\n#include \u003cmeta/factory.hpp\u003e\n#include \u003cmeta/meta.hpp\u003e\n```\n\nThen pass the proper `-I` argument to the compiler to add the `src` directory to\nthe include paths.\n\n## Documentation\n\nThe documentation is based on [doxygen](http://www.stack.nl/~dimitri/doxygen/).\nTo build it:\n\n    $ cd build\n    $ cmake .. -DBUILD_DOCS=ON\n    $ make\n\nThe API reference will be created in HTML format within the directory\n`build/docs/html`. To navigate it with your favorite browser:\n\n    $ cd build\n    $ your_favorite_browser docs/html/index.html\n\n\u003c!--\n@cond TURN_OFF_DOXYGEN\n--\u003e\nIt's also available [online](https://skypjack.github.io/meta/) for the latest\nversion.\n\u003c!--\n@endcond TURN_OFF_DOXYGEN\n--\u003e\n\n## Tests\n\nTo compile and run the tests, `meta` requires *googletest*.\u003cbr/\u003e\n`cmake` will download and compile the library before compiling anything else.\nIn order to build without tests set CMake option `BUILD_TESTING=OFF`.\n\nTo build the most basic set of tests:\n\n* `$ cd build`\n* `$ cmake ..`\n* `$ make`\n* `$ make test`\n\n# Crash course\n\n## Names and identifiers\n\nThe meta system doesn't force the user to use a specific tool when it comes to\nworking with names and identifiers. It does this by offering an API that works\nwith opaque identifiers that for example may or may not be generated by means of\na hashed string.\u003cbr/\u003e\nThis means that users can assign any type of identifier to the meta objects, as\nlong as they are numeric. It doesn't matter if they are generated at runtime, at\ncompile-time or with custom functions.\n\nHowever, the examples in the following sections are all based on\n`std::hash\u003cstd::string_view\u003e` as provided by the standard library. Therefore,\nwhere an identifier is required, it's likely that an instance of this class is\nused as follows:\n\n```cpp\nstd::hash\u003cstd::string_view\u003e hash{};\nauto factory = meta::reflect\u003cmy_type\u003e(hash(\"reflected_type\"));\n```\n\nFor what it's worth, this is likely completely equivalent to:\n\n```cpp\nauto factory = meta::reflect\u003cmy_type\u003e(42);\n```\n\nObviously, human-readable identifiers are more convenient to use and highly\nrecommended.\n\n## Reflection in a nutshell\n\nReflection always starts from real types (users cannot reflect imaginary types\nand it would not make much sense, we wouldn't be talking about reflection\nanymore).\u003cbr/\u003e\nTo _reflect_ a type, the library provides the `reflect` function:\n\n```cpp\nmeta::factory factory = meta::reflect\u003cmy_type\u003e(hash(\"reflected_type\"));\n```\n\nIt accepts the type to reflect as a template parameter and an optional\nidentifier as an argument. Identifiers are important because users can retrieve\nmeta types at runtime by searching for them by _name_. However, there are cases\nin which users can be interested in adding features to a reflected type so that\nthe reflection system can use it correctly under the hood, but they don't want\nto allow searching the type by _name_.\u003cbr/\u003e\nIn both cases, the returned value is a factory object to use to continue\nbuilding the meta type.\n\nA factory is such that all its member functions returns the factory itself.\nIt can be used to extend the reflected type and add the following:\n\n* _Constructors_. Actual constructors can be assigned to a reflected type by\n  specifying their list of arguments. Free functions (namely, factories) can be\n  used as well, as long as the return type is the expected one. From a client's\n  point of view, nothing changes if a constructor is a free function or an\n  actual constructor.\u003cbr/\u003e\n  Use the `ctor` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\")).ctor\u003cint, char\u003e().ctor\u003c\u0026factory\u003e();\n  ```\n\n* _Destructors_. Free functions can be set as destructors of reflected types.\n  The purpose is to give users the ability to free up resources that require\n  special treatment before an object is actually destroyed.\u003cbr/\u003e\n  Use the `dtor` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\")).dtor\u003c\u0026destroy\u003e();\n  ```\n\n  A function should neither delete nor explicitly invoke the destructor of a\n  given instance.\n\n* _Data members_. Both real data members of the underlying type and static and\n  global variables, as well as constants of any kind, can be attached to a meta\n  type. From a client's point of view, all the variables associated with the\n  reflected type will appear as if they were part of the type itself.\u003cbr/\u003e\n  Use the `data` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\"))\n      .data\u003c\u0026my_type::static_variable\u003e(hash(\"static\"))\n      .data\u003c\u0026my_type::data_member\u003e(hash(\"member\"))\n      .data\u003c\u0026global_variable\u003e(hash(\"global\"));\n  ```\n\n  This function requires as an argument the identifier to give to the meta data\n  once created. Users can then access meta data at runtime by searching for them\n  by _name_.\u003cbr/\u003e\n  Data members can be set also by means of a couple of functions, namely a\n  setter and a getter. Setters and getters can be either free functions, member\n  functions or mixed ones, as long as they respect the required signatures.\u003cbr/\u003e\n  Refer to the inline documentation for all the details.\n\n* _Member functions_. Both real member functions of the underlying type and free\n  functions can be attached to a meta type. From a client's point of view, all\n  the functions associated with the reflected type will appear as if they were\n  part of the type itself.\u003cbr/\u003e\n  Use the `func` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\"))\n      .func\u003c\u0026my_type::static_function\u003e(hash(\"static\"))\n      .func\u003c\u0026my_type::member_function\u003e(hash(\"member\"))\n      .func\u003c\u0026free_function\u003e(hash(\"free\"));\n  ```\n\n  This function requires as an argument the identifier to give to the meta\n  function once created. Users can then access meta functions at runtime by\n  searching for them by _name_.\n\n* _Base classes_. A base class is such that the underlying type is actually\n  derived from it. In this case, the reflection system tracks the relationship\n  and allows for implicit casts at runtime when required.\u003cbr/\u003e\n  Use the `base` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cderived_type\u003e(hash(\"derived\")).base\u003cbase_type\u003e();\n  ```\n\n  From now on, wherever a `base_type` is required, an instance of `derived_type`\n  will also be accepted.\n\n* _Conversion functions_. Actual types can be converted, this is a fact. Just\n  think of the relationship between a `double` and an `int` to see it. Similar\n  to bases, conversion functions allow users to define conversions that will be\n  implicitly performed by the reflection system when required.\u003cbr/\u003e\n  Use the `conv` member function for this purpose:\n\n  ```cpp\n  meta::reflect\u003cdouble\u003e().conv\u003cint\u003e();\n  ```\n\nThat's all, everything users need to create meta types and enjoy the reflection\nsystem. At first glance it may not seem that much, but users usually learn to\nappreciate it over time.\u003cbr/\u003e\nAlso, do not forget what these few lines hide under the hood: a built-in,\nnon-intrusive and macro-free system for reflection in C++. Features that are\ndefinitely worth the price, at least for me.\n\n## Any as in any type\n\nThe reflection system comes with its own meta any type. It may seem redundant\nsince C++17 introduced `std::any`, but it is not.\u003cbr/\u003e\nIn fact, the _type_ returned by an `std::any` is a const reference to an\n`std::type_info`, an implementation defined class that's not something everyone\nwants to see in a software. Furthermore, the class `std::type_info` suffers from\nsome design flaws and there is even no way to _convert_ an `std::type_info` into\na meta type, thus linking the two worlds.\n\nA meta any object provides an API similar to that of its most famous counterpart\nand serves the same purpose of being an opaque container for any type of\nvalue.\u003cbr/\u003e\nIt minimizes the allocations required, which are almost absent thanks to _SBO_\ntechniques. In fact, unless users deal with _fat types_ and create instances of\nthem though the reflection system, allocations are at zero.\n\nA meta any object can be created by any other object or as an empty container\nto initialize later:\n\n```cpp\n// a meta any object that contains an int\nmeta::any any{0};\n\n// an empty meta any object\nmeta::any empty{};\n```\n\nIt takes the burden of destroying the contained instance when required.\u003cbr/\u003e\nMoreover, it can be used as an opaque container for unmanaged objects if needed:\n\n```cpp\nint value;\nmeta::any any{std::ref(value)};\n```\n\nIn other words, whenever `any` intercepts a `reference_wrapper`, it acts as a\nreference to the original instance rather than making a copy of it. The\ncontained object is never destroyed and users must ensure that its lifetime\nexceeds that of the container.\n\nA meta any object has a `type` member function that returns the meta type of the\ncontained value, if any. The member functions `try_cast`, `cast` and `convert`\nare used to know if the underlying object has a given type as a base or if it\ncan be converted implicitly to it.\n\n## Enjoy the runtime\n\nOnce the web of reflected types has been constructed, it's a matter of using it\nat runtime where required.\n\nTo search for a reflected type there are two options: by type or by _name_. In\nboth cases, the search can be done by means of the `resolve` function:\n\n```cpp\n// search for a reflected type by type\nmeta::type by_type = meta::resolve\u003cmy_type\u003e();\n\n// search for a reflected type by name\nmeta::type by_name = meta::resolve(hash(\"reflected_type\"));\n```\n\nThere exits also a third overload of the `resolve` function to use to iterate\nall the reflected types at once:\n\n```cpp\nresolve([](meta::type type) {\n    // ...\n});\n```\n\nIn all cases, the returned value is an instance of `type`. This type of objects\noffer an API to know the _runtime identifier_ of the type, to iterate all the\nmeta objects associated with them and even to build or destroy instances of the\nunderlying type.\u003cbr/\u003e\nRefer to the inline documentation for all the details.\n\nThe meta objects that compose a meta type are accessed in the following ways:\n\n* _Meta constructors_. They are accessed by types of arguments:\n\n  ```cpp\n  meta::ctor ctor = meta::resolve\u003cmy_type\u003e().ctor\u003cint, char\u003e();\n  ```\n\n  The returned type is `ctor` and may be invalid if there is no constructor that\n  accepts the supplied arguments or at least some types from which they are\n  derived or to which they can be converted.\u003cbr/\u003e\n  A meta constructor offers an API to know the number of arguments, the expected\n  meta types and to invoke it, therefore to construct a new instance of the\n  underlying type.\n\n* _Meta destructor_. It's returned by a dedicated function:\n\n  ```cpp\n  meta::dtor dtor = meta::resolve\u003cmy_type\u003e().dtor();\n  ```\n\n  The returned type is `dtor` and may be invalid if there is no custom\n  destructor set for the given meta type.\u003cbr/\u003e\n  All what a meta destructor has to offer is a way to invoke it on a given\n  instance. Be aware that the result may not be what is expected.\n\n* _Meta data_. They are accessed by _name_:\n\n  ```cpp\n  meta::data data = meta::resolve\u003cmy_type\u003e().data(hash(\"member\"));\n  ```\n\n  The returned type is `data` and may be invalid if there is no meta data object\n  associated with the given identifier.\u003cbr/\u003e\n  A meta data object offers an API to query the underlying type (ie to know if\n  it's a const or a static one), to get the meta type of the variable and to set\n  or get the contained value.\n\n* _Meta functions_. They are accessed by _name_:\n\n  ```cpp\n  meta::func func = meta::resolve\u003cmy_type\u003e().func(hash(\"member\"));\n  ```\n\n  The returned type is `func` and may be invalid if there is no meta function\n  object associated with the given identifier.\u003cbr/\u003e\n  A meta function object offers an API to query the underlying type (ie to know\n  if it's a const or a static function), to know the number of arguments, the\n  meta return type and the meta types of the parameters. In addition, a meta\n  function object can be used to invoke the underlying function and then get the\n  return value in the form of meta any object.\n\n* _Meta bases_. They are accessed through the _name_ of the base types:\n\n  ```cpp\n  meta::base base = meta::resolve\u003cderived_type\u003e().base(hash(\"base\"));\n  ```\n\n  The returned type is `base` and may be invalid if there is no meta base object\n  associated with the given identifier.\u003cbr/\u003e\n  Meta bases aren't meant to be used directly, even though they are freely\n  accessible. They expose only a few methods to use to know the meta type of the\n  base class and to convert a raw pointer between types.\n\n* _Meta conversion functions_. They are accessed by type:\n\n  ```cpp\n  meta::conv conv = meta::resolve\u003cdouble\u003e().conv\u003cint\u003e();\n  ```\n\n  The returned type is `conv` and may be invalid if there is no meta conversion\n  function associated with the given type.\u003cbr/\u003e\n  The meta conversion functions are as thin as the meta bases and with a very\n  similar interface. The sole difference is that they return a newly created\n  instance wrapped in a meta any object when they convert between different\n  types.\n\nAll the objects thus obtained as well as the meta types can be explicitly\nconverted to a boolean value to check if they are valid:\n\n```cpp\nmeta::func func = meta::resolve\u003cmy_type\u003e().func(hash(\"member\"));\n\nif(func) {\n    // ...\n}\n```\n\nFurthermore, all meta objects with the exception of meta destructors can be\niterated through an overload that accepts a callback through which to return\nthem. As an example:\n\n```cpp\nmeta::resolve\u003cmy_type\u003e().data([](meta::data data) {\n    // ...\n});\n```\n\nA meta type can also be used to `construct` or `destroy` actual instances of the\nunderlying type.\u003cbr/\u003e\nIn particular, the `construct` member function accepts a variable number of\narguments and searches for a match. It returns a `any` object that may or may\nnot be initialized, depending on whether a suitable constructor has been found\nor not. On the other side, the `destroy` member function accepts instances of\n`any` as well as actual objects by reference and invokes the registered\ndestructor if any.\u003cbr/\u003e\nBe aware that the result of a call to `destroy` may not be what is expected. The\npurpose is to give users the ability to free up resources that require special\ntreatment and **not** to actually destroy instances.\n\nMeta types and meta objects in general contain much more than what is said: a\nplethora of functions in addition to those listed whose purposes and uses go\nunfortunately beyond the scope of this document.\u003cbr/\u003e\nI invite anyone interested in the subject to look at the code, experiment and\nread the official documentation to get the best out of this powerful tool.\n\n## Policies: the more, the less\n\nPolicies are a kind of compile-time directives that can be used when recording\nreflection information.\u003cbr/\u003e\nTheir purpose is to require slightly different behavior than the default in some\nspecific cases. For example, when reading a given data member, its value is\nreturned wrapped in a `any` object which, by default, makes a copy of it. For\nlarge objects or if the caller wants to access the original instance, this\nbehavior isn't desirable. Policies are there to offer a solution to this and\nother problems.\n\nThere are a few alternatives available at the moment:\n\n* The _as-is_ policy, associated with the type `meta::as_is_t`.\u003cbr/\u003e\n  This is the default policy. In general, it should never be used explicitly,\n  since it's implicitly selected if no other policy is specified.\u003cbr/\u003e\n  In this case, the return values of the functions as well as the properties\n  exposed as data members are always returned by copy in a dedicated wrapper and\n  therefore associated with their original meta types.\n\n* The _as-void_ policy, associated with the type `meta::as_void_t`.\u003cbr/\u003e\n  Its purpose is to discard the return value of a meta object, whatever it is,\n  thus making it appear as if its type were `void`.\u003cbr/\u003e\n  If the use with functions is obvious, it must be said that it's also possible\n  to use this policy with constructors and data members. In the first case, the\n  constructor will be invoked but the returned wrapper will actually be empty.\n  In the second case, instead, the property will not be accessible for\n  reading.\n\n  As an example of use:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\"))\n      .func\u003c\u0026my_type::member_function, meta::as_void_t\u003e(hash(\"member\"));\n  ```\n\n* The _as-alias_ policy, associated with the type `meta::as_alias_t`\u003cbr/\u003e\n  It allows to build wrappers that act as aliases for the objects used to\n  initialize them. Modifying the object contained in the wrapper for which the\n  _aliasing_ was requested will make it possible to directly modify the instance\n  used to initialize the wrapper itself.\u003cbr/\u003e\n  This policy works with constructors (for example, when objects are taken from\n  an external container rather than created on demand), data members and\n  functions in general (as long as their return types are lvalue references).\n\n  As an example of use:\n\n  ```cpp\n  meta::reflect\u003cmy_type\u003e(hash(\"reflected\"))\n      .data\u003c\u0026my_type::data_member, meta::as_alias_t\u003e(hash(\"member\"));\n  ```\n\nSome uses are rather trivial, but it's useful to note that there are some less\nobvious corner cases that can in turn be solved with the use of policies.\n\n## Named constants and enums\n\nA special mention should be made for constant values and enums. It wouldn't be\nnecessary, but it will help distracted readers.\n\nAs mentioned, the `data` member function can be used to reflect constants of any\ntype among the other things.\u003cbr/\u003e\nThis allows users to create meta types for enums that will work exactly like any\nother meta type built from a class. Similarly, arithmetic types can be enriched\nwith constants of special meaning where required.\u003cbr/\u003e\nPersonally, I find it very useful not to export what is the difference between\nenums and classes in C++ directly in the space of the reflected types.\n\nAll the values thus exported will appear to users as if they were constant data\nmembers of the reflected types.\n\nExporting constant values or elements from an enum is as simple as ever:\n\n```cpp\nmeta::reflect\u003cmy_enum\u003e()\n        .data\u003cmy_enum::a_value\u003e(hash(\"a_value\"))\n        .data\u003cmy_enum::another_value\u003e(hash(\"another_value\"));\n\nmeta::reflect\u003cint\u003e().data\u003c2048\u003e(hash(\"max_int\"));\n```\n\nIt goes without saying that accessing them is trivial as well. It's a matter of\ndoing the following, as with any other data member of a meta type:\n\n```cpp\nmy_enum value = meta::resolve\u003cmy_enum\u003e().data(hash(\"a_value\")).get({}).cast\u003cmy_enum\u003e();\nint max = meta::resolve\u003cint\u003e().data(hash(\"max_int\")).get({}).cast\u003cint\u003e();\n```\n\nAs a side note, remember that all this happens behind the scenes without any\nallocation because of the small object optimization performed by the meta any\nclass.\n\n## Properties and meta objects\n\nSometimes (for example, when it comes to creating an editor) it might be useful\nto be able to attach properties to the meta objects created. Fortunately, this\nis possible for most of them.\u003cbr/\u003e\nTo attach a property to a meta object, no matter what as long as it supports\nproperties, it is sufficient to provide an object at the time of construction\nsuch that `std::get\u003c0\u003e` and `std::get\u003c1\u003e` are valid for it. In other terms, the\nproperties are nothing more than key/value pairs users can put in an\n`std::pair`. As an example:\n\n```cpp\nmeta::reflect\u003cmy_type\u003e(hash(\"reflected\"), std::make_pair(hash(\"tooltip\"), \"message\"));\n```\n\nThe meta objects that support properties offer then a couple of member functions\nnamed `prop` to iterate them at once and to search a specific property by key:\n\n```cpp\n// iterate all the properties of a meta type\nmeta::resolve\u003cmy_type\u003e().prop([](meta::prop prop) {\n    // ...\n});\n\n// search for a given property by name\nmeta::prop prop = meta::resolve\u003cmy_type\u003e().prop(hash(\"tooltip\"));\n```\n\nMeta properties are objects having a fairly poor interface, all in all. They\nonly provide the `key` and the `value` member functions to be used to retrieve\nthe key and the value contained in the form of meta any objects, respectively.\n\n## Unregister types\n\nA type registered with the reflection system can also be unregistered. This\nmeans unregistering all its data members, member functions, conversion functions\nand so on. However, the base classes won't be unregistered, since they don't\nnecessarily depend on it. Similarly, implicitly generated types (as an example,\nthe meta types implicitly generated for function parameters when needed) won't\nbe unregistered.\n\nTo unregister a type, users can use the `unregister` function from the global\nnamespace:\n\n```cpp\nmeta::unregister\u003cmy_type\u003e();\n```\n\nThis function returns a boolean value that is true if the type is actually\nregistered with the reflection system, false otherwise.\u003cbr/\u003e\nThe type can be re-registered later with a completely different name and form.\n\n\u003c!--\n@cond TURN_OFF_DOXYGEN\n--\u003e\n# Contributors\n\nRequests for features, PR, suggestions ad feedback are highly appreciated.\n\nIf you find you can help me and want to contribute to the project with your\nexperience or you do want to get part of the project for some other reasons,\nfeel free to contact me directly (you can find the mail in the\n[profile](https://github.com/skypjack)).\u003cbr/\u003e\nI can't promise that each and every contribution will be accepted, but I can\nassure that I'll do my best to take them all seriously.\n\nIf you decide to participate, please see the guidelines for\n[contributing](docs/CONTRIBUTING.md) before to create issues or pull\nrequests.\u003cbr/\u003e\nTake also a look at the\n[contributors list](https://github.com/skypjack/meta/blob/master/AUTHORS) to\nknow who has participated so far.\n\u003c!--\n@endcond TURN_OFF_DOXYGEN\n--\u003e\n\n# License\n\nCode and documentation Copyright (c) 2018-2019 Michele Caini.\n\nCode released under\n[the MIT license](https://github.com/skypjack/meta/blob/master/LICENSE).\nDocumentation released under\n[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).\u003cbr/\u003e\n\n\u003c!--\n@cond TURN_OFF_DOXYGEN\n--\u003e\n# Support\n\nIf you want to support this project, you can\n[offer me](https://github.com/users/skypjack/sponsorship) an espresso.\u003cbr/\u003e\nIf you find that it's not enough, feel free to\n[help me](https://www.paypal.me/skypjack) the way you prefer.\n\u003c!--\n@endcond TURN_OFF_DOXYGEN\n--\u003e\n","funding_links":["https://github.com/sponsors/skypjack","https://www.paypal.me/skypjack"],"categories":["Reflection","Libraries","映射","Miscellaneous","C++"],"sub_categories":["C++","物理学"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskypjack%2Fmeta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskypjack%2Fmeta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskypjack%2Fmeta/lists"}