This project provides a simple macro to define a member variable along with its chainable setter method in C++17 or later.
- Define member variables and their chainable setters using a single macro
- Improves code readability and reduces boilerplate
- Compatible with C++17 and modern C++ compilers
#include "DefineMemeberAndSetter.hpp"
struct Config {
DEFINE_MEMBER_AND_SETTER(std::string, name)
DEFINE_MEMBER_AND_SETTER(int, width)
DEFINE_MEMBER_AND_SETTER(int, height)
};
Usage:
Config cfg;
// Setter
cfg.name("Main Window")
.width(1280)
.height(720);
// Getter
std::cout << "Name: " << cfg.name() << "\n";
std::cout << "Width: " << cfg.width() << "\n";
std::cout << "Fullscreen: " << std::boolalpha << cfg.fullscreen() << "\n";
mkdir build && cd build
cmake ..
make