Skip to content
/ USRefl Public
forked from Ubpa/USRefl

Header-only, tiny (99 lines) and powerful C++17 static reflection library.

License

Notifications You must be signed in to change notification settings

ztreble/USRefl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


 __    __       _______..______       _______  _______  __      
|  |  |  |     /       ||   _  \     |   ____||   ____||  |     
|  |  |  |    |   (----`|  |_)  |    |  |__   |  |__   |  |     
|  |  |  |     \   \    |      /     |   __|  |   __|  |  |     
|  `--'  | .----)   |   |  |\  \----.|  |____ |  |     |  `----.
 \______/  |_______/    | _| `._____||_______||__|     |_______|
                                                                

repo-size tag license compiler explorer

⭐ Star us on GitHub — it helps!

USRefl

Ubpa Static Reflection

Header-only, tiny (99 lines) and powerful C++17 static reflection library.

Feature

  • header-only, tiny (99 lines) and powerful (USRefl_99.h)
  • noninvasive
  • basic
    • (non-static / static) member variable
    • (non-static / static) member function
  • attribute
  • enum
    • string <-> enumerator
    • static dispatch
  • template
  • inheritance
    • diamond inheritance
    • iterate bases recursively
    • virtual inheritance
  • parser

Example

run it online : compiler explorer

#include <USRefl/USRefl.h>
#include <iostream>
using namespace Ubpa::USRefl;
using namespace std;

// [[...]] act as (structured) comments
// they are useless in the code
struct [[size(8)]] Point {
  [[not_serialize]]
  float x;
  [[info("hello")]]
  float y;
};

// declaration
template<>
struct TypeInfo<Point> : TypeInfoBase<Point> {
  // if you use <USRefl/USRefl.h>, the name is declared by TypeInfoBase<Point>
  // if you use <USRefl_99.h>, you should declare it here.
  // static constexpr std::string_view name = "struct Point";