Giter Club home page Giter Club logo

looking-glass's Introduction

looking-glass


constexpr utilities to determine the number of member fields in an aggregate struct, and produce a std::tuple with the same list of types.

Example usage


// Struct with three member variables
struct S
{
    char a, b, c;
};

// Check that S has three members at compile time
static_assert(glass::member_count<S> == 3, "S does not have 3 members.");
static_assert(std::is_same_v<glass::tuple<S>, std::tuple<char, char, char>>);

Requirements


This lib requires GCC version 9 or above due to a bug fix provided for uniform aggregate initialisation of unions. I haven't traced back the minimum MSVC version yet, but it does work with v19.14 and above.

  • GCC >= 9.0.0
  • Clang >= 4
  • MSVC >= 19.14 (probably lower?)
  • C++17

Build


The utility is header only, simply include "glass.hpp" to use.
There are a couple of customisation options for the header:

  • Define GLASS_NAMESPACE if you want the utilities to live in a namespace other than glass.
  • Disable the compile-time unit tests by defining GLASS_DISABLE_TESTS

Tests


The unit tests have been added as static_asserts (because why not?) and are included at the end of the main header so they are always checked. A dummy translation unit has been provided for easy of checking the compilation:

$(CXX) test/test.cpp

TODO


  • Support for anonymous unions and unnamed structs.
  • Portable across GCC and Clang.
  • Basic unit tests.
  • Configurable namespace.
  • Trace minimum MSVC version.
  • Unit test tuple types with anonymous unions?
  • Continuous integration.

looking-glass's People

Contributors

nitronoid avatar

Stargazers

 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.