{"id":25655561,"url":"https://github.com/hhkit/cpp.property","last_synced_at":"2026-06-22T09:32:33.832Z","repository":{"id":188921059,"uuid":"269612163","full_name":"hhkit/cpp.property","owner":"hhkit","description":"A single-header property system for C++17.","archived":false,"fork":false,"pushed_at":"2020-06-05T17:28:40.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-23T21:36:05.676Z","etag":null,"topics":["cpp","cpp17","getters","properties","property","setters","single-header-lib"],"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/hhkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-06-05T11:17:43.000Z","updated_at":"2020-06-18T11:37:32.000Z","dependencies_parsed_at":"2023-08-17T13:58:12.421Z","dependency_job_id":null,"html_url":"https://github.com/hhkit/cpp.property","commit_stats":null,"previous_names":["hhkit/cpp.property"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hhkit/cpp.property","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhkit%2Fcpp.property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhkit%2Fcpp.property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhkit%2Fcpp.property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhkit%2Fcpp.property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhkit","download_url":"https://codeload.github.com/hhkit/cpp.property/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhkit%2Fcpp.property/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34643614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","cpp17","getters","properties","property","setters","single-header-lib"],"created_at":"2025-02-23T21:31:57.879Z","updated_at":"2026-06-22T09:32:33.814Z","avatar_url":"https://github.com/hhkit.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpp.property\n\nA single-header property class written in C++17 that adds property functionality\nto C++.\n\nNote that C++ was not built to support this for a reason. Enabling properties in\nyour class is not a zero-cost abstraction. In particular, this system has the\nfollowing weaknesses:\n* Properties will set your class's minimum alignment to `alignof(unsigned)`.\n* Properties will add a minimum of `sizeof(unsigned)` bytes to your class, \n  padded to `alignof(unsigned)`.\n* Getters and setters used in the properties must be declared before the \n  properties themselves or the symbol will not be recognized by the compiler,\n  resulting in a compile error.\n\n## Installation\n* Copy `property.hpp` into your project.\n* `#include \"property.hpp\"`\n* ???\n* Profit\n\n## Usage\nA property is constructed using the `fcp::property` template, which takes in\nthree arguments:\n1. `T`, the type of the property.\n2. `GetFn`, a pointer to the getter member function for the property\n   The member function pointed to by GetFn must be `const`-qualified.\n3. `SetFn`, an optional setter for the property.\n\nThe properties must be guarded by the `PROPERTIES_BEGIN()` and \n`PROPERTIES_END()` macros, which hide a union and a `property_offset` object \nthat serves as a helper to determine the `this` pointer of the object. \nChanging the values in the union and adding non-property variables to the \nguard may result in undefined behavior.\n\nExample:\n```cpp\n#include \"property.hpp\"\n#include \u003ciostream\u003e\n\nclass A {\nprivate:\n  int i_ = 5;\n\n  int get_i() const {\n    return i_;\n  }\n\n  void set_i(int new_i) {\n    if (new_i \u003c 0 || new_i \u003e 10)\n      return;\n    i_ = new_i;\n  }\n\n  float get_f() const {\n    return 50.f;\n  }\npublic:\n  PROPERTIES_BEGIN()\n    fcp::property\u003cint, \u0026A::get_i, \u0026A::set_i\u003e i;\n    fcp::property\u003cint, \u0026A::get_f\u003e f;\n  PROPERTIES_END()\n};\n\nint main()\n{\n  A a{};\n\n  a.i = 6;\n  std::cout \u003c\u003c \"a.i: \" \u003c\u003c a.i \u003c\u003c \"\\n\"; // prints 6\n\n  a.i = 20;\n  std::cout \u003c\u003c \"a.i: \" \u003c\u003c a.i \u003c\u003c \"\\n\"; // prints 6\n  \n  // auto error = a.i;                 // will not compile\n  // a.f = 7.f;                        // fails to compile\n  std::cout \u003c\u003c \"a.f: \" \u003c\u003c a.f \u003c\u003c \"\\n\"; // prints 50\n}\n```\n\n## Known Issues\n* MSVC fails to link when default constructing a value without arguments.\n  This is due to an abuse in the language where the this pointer is passed in\n  during aggregate initialization, which MSVC does not invoke when no arguments\n  are provided. To fix this issue, a default constructor must be defined (note:\n  without using `= default`) in the class.\n\n  ```cpp\n  class A\n  {\n  public:\n    A(){} // without this, MSVC will not compile\n    \n    ... // and the rest from the example\n  };\n  \n  int main()\n  {\n    A a;\n  }\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhkit%2Fcpp.property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhkit%2Fcpp.property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhkit%2Fcpp.property/lists"}