2017-03-16 19:45:47 +02:00
|
|
|
[/
|
|
|
|
|
/ Copyright 2017 Peter Dimov
|
|
|
|
|
/
|
|
|
|
|
/ Distributed under the Boost Software License, Version 1.0. (See
|
|
|
|
|
/ accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
|
/ http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
/]
|
|
|
|
|
|
2017-03-17 05:55:27 +02:00
|
|
|
[section Overview]
|
|
|
|
|
|
2017-03-16 19:45:47 +02:00
|
|
|
Mp11 is a C++11 metaprogramming library based on template aliases and variadic templates.
|
|
|
|
|
It implements the approach outlined in the article
|
|
|
|
|
[@http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html Simple C++11 metaprogramming]
|
|
|
|
|
([@http://pdimov.com/cpp2/simple_cxx11_metaprogramming_2.html part 2]).
|
|
|
|
|
|
|
|
|
|
The general principles upon which Mp11 is built are that algorithms and metafunctions are
|
|
|
|
|
template aliases of the form `F<T...>` and data structures are lists of the form `L<T...>`,
|
|
|
|
|
with the library placing no requirements on `L`. `mp_list<T...>` is the built-in list type,
|
|
|
|
|
but `std::tuple<T...>`, `std::pair<T1, T2>` and `std::variant<T...>` are also perfectly
|
2017-03-17 05:55:27 +02:00
|
|
|
legitimate list types, although of course `std::pair<T1, T2>`, due to having exactly two elements,
|
2017-03-16 19:45:47 +02:00
|
|
|
is not resizeable and will consequently not work with algorithms that need to add or remove
|
|
|
|
|
elements.
|
|
|
|
|
|
|
|
|
|
Another distinguishing feature of this approach is that lists (`L<T...>`) have the same form as
|
|
|
|
|
metafunctions (`F<T...>`) and can therefore be used as such. For example, applying `std::add_pointer_t`
|
2017-03-17 05:55:27 +02:00
|
|
|
to the list `std::tuple<int, float>` by way of `mp_transform<std::add_pointer_t, std::tuple<int, float>>`
|
2017-03-16 19:45:47 +02:00
|
|
|
gives us `std::tuple<int*, float*>`, but we can also apply `mp_list` to the same tuple:
|
|
|
|
|
|
2017-03-17 05:55:27 +02:00
|
|
|
using R = mp_transform<mp_list, std::tuple<int, float>>;
|
2017-03-16 19:45:47 +02:00
|
|
|
|
|
|
|
|
and get `std::tuple<mp_list<int>, mp_list<float>>`.
|
2017-03-17 05:55:27 +02:00
|
|
|
|
|
|
|
|
[endsect]
|