1.1. Overview: Quick Start - TheNitesWhoSay/RareCpp GitHub Wiki

Setup/Inclusion

RareCpp is a C++17 header-only library, no special setup/configuration is needed beyond including the headers you're using in your project, ensuring you're using at least C++17, and having a compatible C++ compiler.

It is recommended to do some form of fetching a copy of RareCpp from git, and adding RareCpp's "include" directory to your projects include directories, such that you can: #include <rarecpp/reflect.h> in your project files.

It may be easier for some to copy-paste the header and include it as you do your other project header files. While this works, be aware that the documentation and example code will assume include directories are set and you may need to alter the include statement slightly to use the example.

Header-Only

Download, clone, or copy the headers into your project.

Fetch via CMake

FetchContent_Declare(
  rarecpp
  GIT_REPOSITORY https://github.com/TheNitesWhoSay/RareCpp.git
  GIT_TAG d437771 # release-2.3.2
)
FetchContent_MakeAvailable(rarecpp)
include_directories(${rarecpp_SOURCE_DIR}/include)

Compiler Compatibility

GCC, Clang and MSVC/Visual Studios are directly supported by this library, other compilers, especially those based on the big three may well work regardless; please report issues even with unsupported compilers, though ability to resolve issues on unsupported compilers may be limited.

  • GCC Minimum: 10.1 (10.3.0 and up preferred)
  • Clang Minimum: 9.0.0 (15.0.0 and up preferred)
  • MSVC Minimum: 19.26 (MSVC 19.29/Visual Studios 2019 version 16.11.2 and up preferred)

Simple Example

Once included, you can run a simple code example, e.g. Run

#include <rarecpp/reflect.h>
#include <iostream>

struct MyObj
{
    int a = 42;
    int b = 1337;

    REFLECT(MyObj, a, b)
};

int main()
{
    MyObj myObj{};
    RareTs::Members<MyObj>::forEach(myObj, [&](auto & member, auto & value) {
        std::cout << member.name << ": " << value << std::endl;
    });
    return 0;
}

Which will print:

a: 42
b: 1337

Up Next...

To learn how to code using RareCpp I recommend continuing to one of the following pages...

  • Reflection - teaches how to use the most important capabilities of reflection
  • How To... - provides examples of how to do specific things & relevant documentation links
⚠️ **GitHub.com Fallback** ⚠️