Skip to content

Commit

Permalink
Merge pull request #74 from brunocodutra/develop
Browse files Browse the repository at this point in the history
Metal 1.0
  • Loading branch information
brunocodutra authored Aug 10, 2017
2 parents a185565 + 0ce7e55 commit 1c47e43
Show file tree
Hide file tree
Showing 37 changed files with 621 additions and 890 deletions.
20 changes: 18 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ matrix:
- clang-format-5.0
sources:
- *srcs
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty main'
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main'
key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'

- os: linux
dist: trusty
compiler: g++
env: CXXVER=4.7
addons:
apt:
packages:
- *pkgs
- g++-4.7
sources: *srcs

- os: linux
dist: trusty
compiler: g++
Expand Down Expand Up @@ -229,7 +240,7 @@ matrix:
- libc++abi-dev
sources:
- *srcs
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty main'
- sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main'
key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key'

- os: osx
Expand Down Expand Up @@ -352,3 +363,8 @@ script:
(cd "${METAL_BUILD_PATH}" && ctest --output-on-failure -E ^test.format)
fi
notifications:
webhooks:
urls: https://webhooks.gitter.im/e/f0433b6f1de0942ea9a8
on_success: change
on_failure: always
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ message(STATUS "Configuring Metal ${METAL_VERSION}")
add_header_library(Metal "${METAL_INCLUDE_DIR}/metal.hpp")
set_target_properties(Metal PROPERTIES
INTERFACE_LIB_VERSION ${METAL_VERSION}
INTERFACE_COMPILE_FEATURES cxx_std_14
INTERFACE_COMPILE_FEATURES cxx_std_11
)

deploy_header_library(Metal)
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# Metal - Metaprogramming Algorithms
# Metal [![version]][semver] [![travis.badge]][travis.metal] [![appveyor.badge]][appveyor.metal] [![gitter.badge]][gitter.metal] [![godbolt.badge]][godbolt.metal]

[![version]][semver]
[![travis.badge]][travis.metal]
[![appveyor.badge]][appveyor.metal]
Metal is a single header C++11 library designed to make you love template
metaprogramming.

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

__[Try it online][godbolt.metal]__

## Modern
## Overview

```.cpp
#include <metal.hpp>
Expand Down Expand Up @@ -77,21 +71,24 @@ static_assert(metal::same<sorted, metal::list<y, z, x>>::value, "");
// that and much more!
```
Check out [more examples][examples].
## Quick Start
## Blazing Fast
1. Download [metal.hpp][releases]
2. `# include </path/to/metal.hpp>`
3. Love template metaprogramming
Minutes-long compile times are a thing of the past!
## Blazing Fast
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
The following compilers are continuously tested at
[Travis CI][travis.metal] and [Appveyor CI][appveyor.metal].
| Compiler | Version | Operating System
|-------------------|-----------|-----------------------
| GCC | 4.7 | Ubuntu 14.04 LTS
| GCC | 4.8 | Ubuntu 14.04 LTS
| GCC | 4.9 | Ubuntu 14.04 LTS
| GCC | 5 | Ubuntu 14.04 LTS
Expand Down Expand Up @@ -135,12 +132,19 @@ Metal is distributed under the
[appveyor.metal]: http://ci.appveyor.com/project/brunocodutra/metal
[appveyor.badge]: http://ci.appveyor.com/api/projects/status/85pk8n05n4r5x103/branch/master?svg=true
[gitter.metal]: http://gitter.im/brunocodutra/metal?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
[gitter.badge]: http://badges.gitter.im/brunocodutra/metal.svg
[godbolt.metal]: http://godbolt.org/g/RFwvic
[godbolt.badge]: http://img.shields.io/badge/try%20it-on%20godbolt-222266.svg
[boost.license]: http://boost.org/LICENSE_1_0.txt
[CMake]: http://cmake.org/
[Doxygen]: http://doxygen.org/
[metaben.ch]: http://metaben.ch/
[releases]: http://github.com/brunocodutra/metal/releases
[documentation]: http://brunocodutra.github.io/metal
[examples]: http://brunocodutra.github.io/metal/#examples
[SFINAE]: http://brunocodutra.github.io/metal/#SFINAE
6 changes: 6 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ build_script:
) else (
pushd "%METAL_BUILD_PATH%" && ctest -C "%CONFIGURATION%" --output-on-failure -E ^test.format & popd
)

notifications:
- provider: Webhook
url: https://webhooks.gitter.im/e/5daddf3d6cedeb27ba90
on_build_failure: true
on_build_status_changed: true
29 changes: 8 additions & 21 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

\tableofcontents

Metal is a header-only C++14 library designed to make template metaprogramming
intuitive. It provides a powerful high-level abstraction for compile-time
algorithms that mimic the Standard Algorithms Library, hence
**Metal** - <b>Meta</b>programming <b>Al</b>gorithms.
Metal is a single header C++11 library designed to make you love template
metaprogramming.

There is a myriad of C++ metaprogramming libraries out there so why Metal?

* **Portable** - compatible with the
[most popular compilers][Metal.portable].
* **Blazing fast** - browse up to date benchmarks at [metaben.ch].
* **Trivial Integration** - everything you need in a single self-contained
* **Trivial Integration** - everything you need in a single self-contained
header file [`metal.hpp`][Metal.standalone].
* **SFINAE-Friendly** - [control overload resolution](#SFINAE) and make the most
out of function templates.

In a Glimpse {#in_a_glimpse}
Overview {#overview}
================================================================================

\snippet tutorial.cpp tutorial

**[Try it online][godbolt.metal]!**

Be sure to also have a look at the [examples](#examples) below.

Definitions {#definitions}
================================================================================

Expand Down Expand Up @@ -234,7 +228,7 @@ you might have come up with something like this
\snippet literal.cpp naive_1
}

only to realize the hard way that this is simply not valid C++14.
only to realize the hard way that this is simply not valid C++.

> error: non-type template argument is not a constant expression
Expand Down Expand Up @@ -590,14 +584,12 @@ but also for numerical values
Again, this only works as expected because of the strict SFINAE-friendliness
guarantees provided by Metal.

Getting Started {#getting_started}
Quick Start {#quick_start}
================================================================================

Metal is distributed as a drop-in standalone header file and integrating it in
your project is as easy as it gets:

1. Download the [latest release][Metal.releases]
1. Download [metal.hpp][Metal.releases]
2. `# include </path/to/metal.hpp>`
3. Love template metaprogramming

Migrating from Boost.MPL {#MPL}
================================================================================
Expand Down Expand Up @@ -731,15 +723,12 @@ the binary representation of numerical values is entirely irrelevant.
[Map]: #map
[Maps]: #map

[C++14]: http://en.wikipedia.org/wiki/C%2B%2B14
[JavaScript]: http://en.wikipedia.org/wiki/JavaScript
[higher-order]: http://en.wikipedia.org/wiki/Higher-order_function
[first-class]: http://en.wikipedia.org/wiki/First-class_citizen
[fold]: http://en.wikipedia.org/wiki/Fold_(higher-order_function)
[church]: http://en.wikipedia.org/wiki/Church_encoding#Church_Booleans
[lambda notation]: http://en.wikipedia.org/wiki/Lambda_calculus

[algorithm]: http://en.cppreference.com/w/cpp/algorithm
[alias templates]: http://en.cppreference.com/w/cpp/language/type_alias
[constexpr]: http://en.cppreference.com/w/cpp/language/constexpr
[tuple]: http://en.cppreference.com/w/cpp/utility/tuple
Expand All @@ -751,8 +740,6 @@ the binary representation of numerical values is entirely irrelevant.
[SFINAE]: http://en.cppreference.com/w/cpp/language/sfinae
[RAII]: http://en.cppreference.com/w/cpp/language/raii

[godbolt.metal]: https://godbolt.org/g/JN13FQ

[travis.metal]: http://travis-ci.org/brunocodutra/metal
[appveyor.metal]: http://ci.appveyor.com/project/brunocodutra/metal

Expand Down
8 changes: 8 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ else()
endif()

test_units(example Metal "${CMAKE_CURRENT_SOURCE_DIR}/src/" EXCLUDE ${exclude})
foreach(target example.literal example.sfinae)
if(TARGET ${target})
set_target_properties(${target} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED OFF
)
endif()
endforeach()

add_custom_target(examples DEPENDS example)
20 changes: 13 additions & 7 deletions example/src/lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@

HIDE(
/// [lbd1]
using lbd = metal::lambda<std::add_pointer_t>;
template<typename T>
using expr = T*;

using lbd = metal::lambda<expr>;
/// [lbd1]

IS_SAME(metal::is_lambda<lbd>, metal::true_);
)

HIDE(
/// [is_lambda]
template<typename T>
using expr = T*;

IS_SAME(metal::is_lambda<void>, metal::false_);
IS_SAME(metal::is_lambda<metal::lambda<std::add_pointer_t>>, metal::true_);
IS_SAME(metal::is_lambda<metal::lambda<expr>>, metal::true_);
IS_SAME(metal::is_lambda<metal::trait<std::is_pointer>>, metal::true_);
IS_SAME(metal::is_lambda<metal::lazy<std::add_pointer>>, metal::true_);
/// [is_lambda]
Expand Down Expand Up @@ -99,23 +105,23 @@ IS_SAME(metal::invoke<metal::arg<4>, bool, char, long, float>, float);

HIDE(
/// [invoke]
using lbd = metal::lambda<std::common_type_t>;
using lbd = metal::lazy<std::common_type>;

IS_SAME(metal::invoke<lbd, bool, char, long, float>, float);
/// [invoke]
)

HIDE(
/// [apply]
using lbd = metal::lambda<std::common_type_t>;
using lbd = metal::lazy<std::common_type>;

IS_SAME(metal::apply<lbd, metal::list<bool, char, long, float>>, float);
/// [apply]
)

HIDE(
/// [partial]
using promote = metal::partial<metal::lambda<std::common_type_t>, int>;
using promote = metal::partial<metal::lazy<std::common_type>, int>;

IS_SAME(metal::invoke<promote, char>, int);
IS_SAME(metal::invoke<promote, short>, int);
Expand All @@ -126,7 +132,7 @@ IS_SAME(metal::invoke<promote, long>, long);
HIDE(
/// [bind]
using promote = metal::bind<
metal::lambda<std::common_type_t>,
metal::lazy<std::common_type>,
metal::always<int>,
metal::_1 // equivalent to metal::arg<1>
>;
Expand All @@ -136,7 +142,7 @@ IS_SAME(metal::invoke<promote, short>, int);
IS_SAME(metal::invoke<promote, long>, long);

using uac = metal::bind< // usual arithmetic conversion
metal::lambda<std::common_type_t>,
metal::lazy<std::common_type>,
metal::bind<promote, metal::_1>,
metal::bind<promote, metal::_2>
>;
Expand Down
6 changes: 4 additions & 2 deletions example/src/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ IS_SAME(

HIDE(
/// [repeat]
IS_SAME(metal::repeat<char, metal::number<0>>, metal::list<>);
IS_SAME(metal::repeat<char, metal::number<3>>, metal::list<char, char, char>);
IS_SAME(metal::repeat<void, metal::number<0>>, metal::list<>);
IS_SAME(metal::repeat<void, metal::number<3>>, metal::list<void, void, void>);
/// [repeat]
)

Expand Down Expand Up @@ -661,6 +661,7 @@ IS_SAME(
/// [transpose]
)

#if !defined(METAL_WORKAROUND)
HIDE(
/// [accumulate]
template<typename val, typename num>
Expand All @@ -685,3 +686,4 @@ IS_SAME(
);
/// [accumulate]
)
#endif
52 changes: 28 additions & 24 deletions example/src/literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,35 @@ IS_SAME(metal::remove<tokens, metal::number<'\''>>, metal::numbers<'3', '7', '1'
#endif

///[parse_digit]
template<typename c>
using parse_digit = metal::if_<
metal::same<c, metal::number<'0'>>, metal::number<0>,
metal::same<c, metal::number<'1'>>, metal::number<1>,
metal::same<c, metal::number<'2'>>, metal::number<2>,
metal::same<c, metal::number<'3'>>, metal::number<3>,
metal::same<c, metal::number<'4'>>, metal::number<4>,
metal::same<c, metal::number<'5'>>, metal::number<5>,
metal::same<c, metal::number<'6'>>, metal::number<6>,
metal::same<c, metal::number<'7'>>, metal::number<7>,
metal::same<c, metal::number<'8'>>, metal::number<8>,
metal::same<c, metal::number<'9'>>, metal::number<9>,
metal::same<c, metal::number<'a'>>, metal::number<10>,
metal::same<c, metal::number<'b'>>, metal::number<11>,
metal::same<c, metal::number<'c'>>, metal::number<12>,
metal::same<c, metal::number<'d'>>, metal::number<13>,
metal::same<c, metal::number<'e'>>, metal::number<14>,
metal::same<c, metal::number<'f'>>, metal::number<15>,
metal::same<c, metal::number<'A'>>, metal::number<10>,
metal::same<c, metal::number<'B'>>, metal::number<11>,
metal::same<c, metal::number<'C'>>, metal::number<12>,
metal::same<c, metal::number<'D'>>, metal::number<13>,
metal::same<c, metal::number<'E'>>, metal::number<14>,
metal::same<c, metal::number<'F'>>, metal::number<15>
template<typename token>
using parse_digit = metal::at_key<
metal::map<
metal::pair<metal::number<'0'>, metal::number<0>>,
metal::pair<metal::number<'1'>, metal::number<1>>,
metal::pair<metal::number<'2'>, metal::number<2>>,
metal::pair<metal::number<'3'>, metal::number<3>>,
metal::pair<metal::number<'4'>, metal::number<4>>,
metal::pair<metal::number<'5'>, metal::number<5>>,
metal::pair<metal::number<'6'>, metal::number<6>>,
metal::pair<metal::number<'7'>, metal::number<7>>,
metal::pair<metal::number<'8'>, metal::number<8>>,
metal::pair<metal::number<'9'>, metal::number<9>>,
metal::pair<metal::number<'a'>, metal::number<10>>,
metal::pair<metal::number<'b'>, metal::number<11>>,
metal::pair<metal::number<'c'>, metal::number<12>>,
metal::pair<metal::number<'d'>, metal::number<13>>,
metal::pair<metal::number<'e'>, metal::number<14>>,
metal::pair<metal::number<'f'>, metal::number<15>>,
metal::pair<metal::number<'A'>, metal::number<10>>,
metal::pair<metal::number<'B'>, metal::number<11>>,
metal::pair<metal::number<'C'>, metal::number<12>>,
metal::pair<metal::number<'D'>, metal::number<13>>,
metal::pair<metal::number<'E'>, metal::number<14>>,
metal::pair<metal::number<'F'>, metal::number<15>>
>,
token
>;

///[parse_digit]

HIDE(
Expand Down
6 changes: 3 additions & 3 deletions example/src/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ IS_SAME(

HIDE(
/// [if_]
IS_SAME(metal::if_<metal::false_, int, metal::number<0>, int*, void>, void);
IS_SAME(metal::if_<metal::false_, int, metal::number<1>, int*, void>, int*);
IS_SAME(metal::if_<metal::true_, int, metal::number<1>, int*, void>, int);
IS_SAME(metal::if_<metal::true_, int>, int);
IS_SAME(metal::if_<metal::true_, int, void>, int);
IS_SAME(metal::if_<metal::false_, int, void>, void);
/// [if_]
)

Expand Down
Loading

0 comments on commit 1c47e43

Please # to comment.