GithubHelp home page GithubHelp logo

remotion / aggregatestotuples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dwarfobserver/aggregatestotuples

0.0 2.0 0.0 207 KB

C++ header-only library which enable using aggregates like tuples

License: MIT License

CMake 0.20% Python 0.15% C++ 99.65%

aggregatestotuples's Introduction

GCC Build Status MSVC Build Status

Aggregates to tuples

This is a single-header library in partial C++17 which enable to treat aggregate (or record) types as tuples. It works for MSVC, Clang and GCC. It has been inspired by this nice article : https://playfulprogramming.blogspot.ca/2016/12/serializing-structs-with-c17-structured.html

Using tuples instead of aggregates can allow many functional programming algorithms and automatic properties, such as equality comparaison, serialization or hash.

There is no documentation for now, tests can be used as a replacement.

Overview of some features :

struct info {
    int age;
    int size;
};
struct person {
    std::string name;
    info infos;
};

auto alex = person { "Alex", { 24, 182 } };

size_t hash = att::hash(alex); // combinaison of string hash and two int hash

using namespace att::operators;

std::ostringstream stream;
stream << alex;                // stream.str() == "{ Alex , { 24 , 182 } }"

person alex2;
stream >> alex2;

bool eq = alex == alex2;       // true

alex2.infos.size += 1;

bool lt = alex < alex2;        // true

att::as_tuple_t<person> refs  = att::as_tuple(alex); // std::tuple<std::string&, info&>
att::to_tuple_t<person> tuple = att::to_tuple(alex); // std::tuple<std::string, info>

auto alex3 = att::from_tuple(refs).make<person>();

Tests can be built and launched with :

mkdir build
cd build
cmake ..
cmake --build .
ctest -V

'single_include/aggregates_to_tuples.hpp' and 'include/arity_functions.inl' are created by the programs contained in 'generators'.

The python file 'full_build.py' can be called from your build directory (which must be in the root directory of the project) to build and execute generators, then build and launch tests.

Project limitations :

  • The aggregate max size is limited (it can be increased with the arity_functions generator)
  • It does not support aggregates with native arrays (eg. T[N], use std::array<T, N> instead)

Note : std::is_aggregate is not used because it is not implemented in MSVC (and not Clang from what I saw), but it would avoid some types detection caveats and greatly reduce compile time.

aggregatestotuples's People

Contributors

dwarfobserver avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.