8000 GitHub - Rhidian12/StructToTuple: A C++20 header-only library to convert Structs to Tuples, and Tuples to Structs!
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rhidian12/StructToTuple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

StructToTuple

A C++20 header-only library to convert Structs to Tuples, and Tuples to Structs! Nested structs and tuples are also fully supported!

The functions are fully constexpr so they can be used at both compile- and runtime. A C++20 compiler is required, but changes to make it C++17 friendly should be very simple.

Usage

Converting any Struct to a std::tuple is as simple as calling StT::StructToTuple(struct)

struct FooBar
{
  int a;
  int b;
  int c;
};
auto [a, b, c] = StT::StructToTuple(FooBar{});
std::tuple<int, int, int> = StT::StructToTuple(FooBar{});

Converting any tuple to a struct is as simple as calling StT::TupleToStruct<Struct>(tuple). Note that the Struct must be given as a template parameter

struct FooBar
{
  int a;
  int b;
  int c;
};
FooBar foo = StT::TupleToStruct<FooBar>(std::tuple<int, int, int>());

About

A C++20 header-only library to convert Structs to Tuples, and Tuples to Structs!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0