Code Monkey home page Code Monkey logo

type_list's Introduction

mz::type_list MIT license C++17 Sponsor Gitter

A variadic 'type list' for performing operations on lists of types in metaprogramming contexts. Optimized to be much more compiler-friendly than std::tuple.

See Compilation speed humps: std::tuple for a write-up on the sorts of optimizations applied herein.

Requires C++17.


Synopsis

namespace mz
{
	template <typename... T>
	struct type_list
	{
		// get the number of types in the list:
		static constexpr size_t length = sizeof...(T);

		// index of the first appearance of the specified type:
		template <typename U>
		static constexpr size_t index_of = /* ... */;

		// determine if a specified type appears in the list:
		template <typename U>
		static constexpr bool contains = /* ... */;

		// get a specific type:
		template <size_t Index>
		using select = /* T...[Index] */;

		// convenience alias for select<0>:
		using first = select<0>;

		// convenience alias for select<0> when length == 1:
		using type = select<0>;

		// get a 'slice' (sublist):
		template <size_t Start, size_t Length = (length - Start)>
		using slice = type_list</* ... */>;

		// adding on to the beginning of the list:
		template <typename... U>
		using prepend = type_list<U..., T...>;

		// adding on to the end of the list:
		template <typename... U>
		using append = type_list<T..., U...>;

		// recursively flatten child sublists:
		using flatten = type_list</* ... */>;

		// remove all occurrences of the specified type:
		template <typename U>
		using remove = type_list</* ... */>;
	};

	// alias for a single-element list:
	template <typename T>
	using type_tag = type_list<T>;
}

Usage

The library is a single header so the easiest way to use it is to drop type_list.hpp somewhere in your project.

Alternatively you can add include to your include paths then #include <mz/type_list.hpp>

There is also support for use as a meson.build subproject.


Benchmarks

Single-threaded compilation of the example application on my Ryzen 3950X:

Clang 12 GCC 10 MSVC 19.29
std::tuple 6.448s 3.185s 7.965s
mz::type_list 0.303s 0.407s 0.830s
speedup factor 21.2x faster 7.8x faster 9.6x faster

License

MIT. See LICENSE.


Contributing

There are three ways you can contribute:

  1. Reporting bug or making feature requests here
  2. Opening a pull request (⚠️ caveat - see below)
  3. Becoming a sponsor ❤️

Pull requests

type_list.hpp is programmatically extracted from a much larger project so I won't accept pull requests made for this repository directly; if you wish to contribute a bugfix or a feature, please find the type_list implementation in this project and propose your changes there instead. I will then propagate them to this satellite library when they are merged.

type_list's People

Contributors

marzer 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.