Git Product home page Git Product logo

metal's Introduction

Metal - Metaprogramming Algorithms

version travis.badge appveyor.badge

Metal is a header-only C++14 library designed to make template metaprogramming intuitive.

Try it online

Modern

#include <metal.hpp>

// First we need some Values
union x { char payload[10]; };
class y { public: char c; };
struct z { char c; int i; };

// ... from which we construct some Lists
using l0 = metal::list<>;
using l1 = metal::prepend<l0, x>;
using l2 = metal::append<l1, z>;
using l3 = metal::insert<l2, metal::number<1>, y>;

static_assert(metal::same<l1, metal::list<x>>::value, "");
static_assert(metal::same<l2, metal::list<x, z>>::value, "");
static_assert(metal::same<l3, metal::list<x, y, z>>::value, "");

// Lists are versatile, we can check their sizes...
static_assert(metal::size<l0>::value == 0, "");
static_assert(metal::size<l1>::value == 1, "");
static_assert(metal::size<l2>::value == 2, "");
static_assert(metal::size<l3>::value == 3, "");

// retrieve their elements...
static_assert(metal::same<metal::front<l3>, x>::value, "");
static_assert(metal::same<metal::back<l3>, z>::value, "");
static_assert(metal::same<metal::at<l3, metal::number<1>>, y>::value, "");

// count those that satisfy a predicate...
static_assert(metal::count_if<l3, metal::trait<std::is_class>>::value == 2, "");
static_assert(metal::count_if<l3, metal::trait<std::is_union>>::value == 1, "");

// We can create new Lists by removing elements...
using l0_ = metal::drop<l3, metal::number<3>>;
using l1_ = metal::take<l3, metal::number<1>>;
using l2_ = metal::erase<l3, metal::number<1>>;

static_assert(metal::same<l0, l0_>::value, "");
static_assert(metal::same<l1, l1_>::value, "");
static_assert(metal::same<l2, l2_>::value, "");

// by reversing the order of elements...
static_assert(metal::same<metal::reverse<l0>, metal::list<>>::value, "");
static_assert(metal::same<metal::reverse<l1>, metal::list<x>>::value, "");
static_assert(metal::same<metal::reverse<l2>, metal::list<z, x>>::value, "");
static_assert(metal::same<metal::reverse<l3>, metal::list<z, y, x>>::value, "");

// by transforming the elements...
using l2ptrs = metal::transform<metal::lazy<std::add_pointer>, l2>;
using l3refs = metal::transform<metal::lazy<std::add_lvalue_reference>, l3>;

static_assert(metal::same<l2ptrs, metal::list<x*, z*>>::value, "");
static_assert(metal::same<l3refs, metal::list<x&, y&, z&>>::value, "");

// even by sorting them...
template<typename x, typename y>
using smaller = metal::number<(sizeof(x) < sizeof(y))>;

using sorted = metal::sort<l3, metal::lambda<smaller>>;

static_assert(metal::same<sorted, metal::list<y, z, x>>::value, "");

// that and much more!

Check out more examples.

Blazing Fast

Minutes-long compile times are a thing of the past!

You don't have to just take my word for it, see for yourself at metaben.ch.

Portable

Don't worry, all your favourite compilers are continuously tested at Travis CI and Appveyor CI.

Compiler Version Operating System
GCC 4.8 Ubuntu 14.04 LTS
GCC 4.9 Ubuntu 14.04 LTS
GCC 5 Ubuntu 14.04 LTS
GCC 6 Ubuntu 14.04 LTS
GCC 7 Ubuntu 14.04 LTS
Clang 3.4 Ubuntu 14.04 LTS
Clang 3.5 Ubuntu 14.04 LTS
Clang 3.6 Ubuntu 14.04 LTS
Clang 3.7 Ubuntu 14.04 LTS
Clang 3.8 Ubuntu 14.04 LTS
Clang 3.9 Ubuntu 14.04 LTS
Clang 4.0 Ubuntu 14.04 LTS
Clang 5.0 Ubuntu 14.04 LTS
Xcode 6.4 OS X 10.10
Xcode 7.3 OS X 10.11
Xcode 8.0 OS X 10.11
Xcode 8.1 OS X 10.12
Xcode 8.2 OS X 10.12
MinGW-w64 5 Windows Server 2012 R2
MinGW-w64 6 Windows Server 2012 R2
Visual Studio 14 (2015) Windows Server 2012 R2
Visual Studio 15 (2017) Windows Server 2016

Documentation

The complete up to date documentation is available online.

License

Metal is distributed under the Boost Software License, Version 1.0.

metal's People

Contributors

brunocodutra avatar fernandoandreotti avatar

Forkers

bhanug

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.