std::tuple like methods for user defined types without any macro or boilerplate code

Related tags

Reflection magic_get
Overview

Boost.PFR

This is a C++14 library for very basic reflection that gives you access to structure elements by index and provides other std::tuple like methods for user defined types without any macro or boilerplate code.

Latest documentation

Test results

Branches Build Tests coverage More info
Develop: Build Status Build status Coverage Status details...
Master: Build Status Build status Coverage Status details...

Motivating Example #0

#include <iostream>
#include <fstream>
#include <string>

#include "boost/pfr.hpp"

struct some_person {
  std::string name;
  unsigned birth_year;
};

int main(int argc, const char* argv[]) {
  some_person val{"Edgar Allan Poe", 1809};

  std::cout << boost::pfr::get<0>(val)                // No macro!
      << " was born in " << boost::pfr::get<1>(val);  // Works with any aggregate initializables!

  if (argc > 1) {
    std::ofstream ofs(argv[1]);
    ofs << boost::pfr::io(val);                       // File now contains: {"Edgar Allan Poe", 1809}
  }
}

Outputs:

Edgar Allan Poe was born in 1809

Motivating Example #1

#include <iostream>
#include "boost/pfr/precise.hpp"

struct my_struct { // no ostream operator defined!
    int i;
    char c;
    double d;
};

int main() {
    my_struct s{100, 'H', 3.141593};
    std::cout << "my_struct has " << boost::pfr::tuple_size<my_struct>::value
        << " fields: " << boost::pfr::io(s) << "\n";
}

Outputs:

my_struct has 3 fields: {100, H, 3.14159}

Motivating Example #2

#include <iostream>
#include "boost/pfr/precise.hpp"

struct my_struct { // no ostream operator defined!
    std::string s;
    int i;
};

int main() {
    my_struct s{{"Das ist fantastisch!"}, 100};
    std::cout << "my_struct has " << boost::pfr::tuple_size<my_struct>::value
        << " fields: " << boost::pfr::io(s) << "\n";
}

Outputs:

my_struct has 2 fields: {"Das ist fantastisch!", 100}

Requirements and Limitations

See docs.

License

Distributed under the Boost Software License, Version 1.0.

Releases(2.0.2)
  • 2.0.2(May 19, 2021)

    • A MurMur Hash based implementation of hash_combine() is now used to reduce collisions count and improve quality of boost::pfr::hash_value()
    • Visual Studio 2017 now supported in C++14 mode (thanks to Denis Mikhailov aka @denzor200)
    • Issues found by inspect tool were fixed
    • Fixed some warnings, including removal of extra semicolons in include/boost/pfr/detail/fields_count.hpp (fixes #72)
    • Added a compile time assert for inherited types (thanks to Denis Mikhailov aka @denzor200)
    • Reflection of aggregates with non movable fields is now possible if guaranteed copy elision is on
    • Fixed spelling issues
    Source code(tar.gz)
    Source code(zip)
  • 2.0.1(Dec 18, 2020)

    • Comparison functions are now constexpr
    • Aggregates with members that have lost const qualifiers on SFINAE in constructor (like std::optional<std::chrono::duration<A,B>> from libc++) now could be reflected again
    • Multiple typos fixed
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Nov 27, 2020)

    First Boost release of the library. Significant changes since version 1.0.x:

    • Removed the Flat reflection
    • Removed global_ops.hpp
    • boost::pfr::ops::operator* were changed to functions and moved to boost::pfr:: namespace
    • Big rewrite of docs
    • Better testing and improved diagnostics
    • Helper script now works with Python2 and Python3
    Source code(tar.gz)
    Source code(zip)
Header-only, non-intrusive and macro-free runtime reflection system in C++

Header-only runtime reflection system in C++ The reflection system was born within EnTT and is developed and enriched there. This project is designed

Michele Caini 418 Jun 21, 2022
Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum

_ _ __ _____ | \ | | / _| / ____|_ _ | \| | __ _ _ __ ___ ___ ___ | |_ | | _| |

Daniil Goncharov 1.4k Jun 20, 2022
std::tuple like methods for user defined types without any macro or boilerplate code

Boost.PFR This is a C++14 library for very basic reflection that gives you access to structure elements by index and provides other std::tuple like me

Boost.org 1k Jun 21, 2022
Gesture-Detecting-Macro-Keyboard - Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32.

Gesture detection tldr; Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32. Main feat

Jakob Krantz 63 Jun 19, 2022
WTD is a python tool for replacing values with the C preprocessor macro which defined them.

Where's That Define WTD is a python tool for replacing values with the C preprocessor macro which defined them. An example of this is when trying to u

Caleb Connolly 5 Mar 28, 2022
Shpp - Call c++ functions from a shell with any arguments of any types parsed automatically

shpp Call c++ functions from a shell with any arguments of any types parsed automatically Declare a variable or define a function and register it in s

Pedro Moreira 96 Jun 8, 2022
Tuple but with tags.

tagged_tuple Tuple but with tags. Example code: #include <iostream> #include "tagged_tuple.hpp" int main() { // defines binding between types (na

null 2 Nov 17, 2021
A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iterating over those.

cpp_enum_set A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iter

Carl Dehlin 22 Jun 16, 2022
C++ functions matching the interface and behavior of python string methods with std::string

Pystring is a collection of C++ functions which match the interface and behavior of python's string class methods using std::string. Implemented in C+

Sony Pictures Imageworks 724 Jun 24, 2022
About Add any Program in any language you like or add a hello world Program ❣️ if you like give us ⭐

Hello-World About Add any Program in any language you like or add a hello world Program ❣️ if you like give us ⭐ Give this Project a Star ⭐ If you lik

Lokesh Jangid 16 Jan 22, 2022
A collection of multiple types of lists used during pentesting, collected in one place. List types include usernames, passwords, combos, wordlist and may more..

Access list is a collection of multiple types of lists used during pentesting, collected in one place, created by Undercode This list include a collec

UNDERCODE UTILITIES 7 Jan 6, 2022
Arbitrary Precision provides C++ long integer types that behave as basic integer types. This library aims to be intuitive and versatile in usage, rather than fast.

Arbitrary Precision (AP) Cross-platform and cross-standard header-only arbitrary precision arithmetic library. Currently it offers integer types that

null 15 May 19, 2022
Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more

fu2::function an improved drop-in replacement to std::function Provides improved implementations of std::function: copyable fu2::function move-only fu

Denis Blank 391 Jun 18, 2022
Fast C++ container combining the best features of std::vector and std::deque

veque The double-ended vector A very fast C++17 container combining the best features of std::vector and std::deque "In Most Cases, Prefer Using deque

null 97 May 4, 2022
Invoke.hpp - std::invoke/std::apply analogs for C++11/14

invoke.hpp std::invoke/std::apply analogs for C++11/14 Requirements gcc >= 4.9 clang >= 3.8 msvc >= 2015 Installation invoke.hpp is a header-only libr

Matvey Cherevko 32 Apr 27, 2022
Cpp-std-fwd - forward declarations for C++ std headers

cpp-std-fwd Forward declarations for most useful runtime classes of the C++ 17 standard library. DISCLAIMER: This project is meant as a proof-of-conce

Philip Trettner 66 Apr 22, 2022
A C++14 macro to get the type of the current class without naming it

self_macro C++14 header only library that exposes a macro that creates a type alias for the current class without naming it. Also exposes macros that

Mital Ashok 8 Jan 14, 2022
Loads a signed kernel driver which allows you to map any driver to kernel mode without any traces of the signed / mapped driver.

CosMapper Loads a signed kernel driver (signed with leaked cert) which allows you to map any driver to kernel mode without any traces of the signed /

null 107 Jul 2, 2022
Automatically load dlls into any executables without replacing any files!

Automatically loaded dll using xinput9_1_0 proxy. Please put the modified xinput9_1_0.dll in the executable's directory.

null 11 Apr 17, 2022
Cobalt Strike User-Defined Reflective Loader written in Assembly & C for advanced evasion capabilities.

Cobalt Strike User-Defined Reflective Loader Cobalt Strike User-Defined Reflective Loader written in Assembly & C for advanced evasion capabilities. B

Bobby Cooke 708 Jun 27, 2022
A header only C++ library that provides type safety and user defined literals for physical units

SI - Type safety for physical units A header only c++ library that provides type safety and user defined literals for handling pyhsical values defined

Dominik Berner 374 Jun 15, 2022
Samir Teymurov 1 Oct 6, 2021
My_Shell is a user-defined interactive shell written in C that works similar to the original shell in linux

MY_SHELL Overview My_Shell is a user-defined interactive shell written in C that works similar to the original shell and it can execeute many of the l

Greeshma 1 Nov 22, 2021
BokuLoader - Cobalt Strike User-Defined Reflective Loader written in Assembly & C for advanced evasion capabilities.

BokuLoader - Cobalt Strike Reflective Loader Cobalt Strike User-Defined Reflective Loader written in Assembly & C for advanced evasion capabilities. B

Bobby Cooke 706 Jun 24, 2022
ToPS is an objected-oriented framework implemented using C++ that facilitates the integration of probabilistic models for sequences over a user defined alphabet

ToPS is an objected-oriented framework implemented using C++ that facilitates the integration of probabilistic models for sequences over a user defined alphabet

Andre Yoshiaki Kashiwabara 35 Mar 6, 2022
A CMake addon that avoids you writing boilerplate code for resource management.

SHader INJ(I)ector SHINJI (originally SHader INJector) is a CMake addon that avoids you writing boilerplate code for resource management and exposes s

Lorenzo Rutayisire 6 Mar 21, 2022