diff --git a/doc/html/mp11.html b/doc/html/mp11.html index db32cd8..b1cc0c6 100644 --- a/doc/html/mp11.html +++ b/doc/html/mp11.html @@ -179,8 +179,9 @@

Mp11 is a C++11 metaprogramming library based on template aliases and variadic templates. It implements the approach outlined in the article Simple - C++11 metaprogramming (part - 2). + C++11 metaprogramming and its + sequel. Reading these articles before proceeding with this documentation + is highly recommended.

The general principles upon which Mp11 is built are that algorithms and metafunctions @@ -322,7 +323,8 @@ using T3 = decltype( T1() + T2() ); using T4 = result<T1, T2>; - std::cout << ( std::is_same<T3, T4>::value? "[PASS] ": "[FAIL] " ) << name<T1>() << " + " << name<T2>() << " -> " << name<T3>() << ", result: " << name<T4>() << " " << std::endl; + std::cout << ( std::is_same<T3, T4>::value? "[PASS] ": "[FAIL] " ) + << name<T1>() << " + " << name<T2>() << " -> " << name<T3>() << ", result: " << name<T4>() << std::endl; } int main() @@ -707,7 +709,7 @@

template<template<class...> class F, class L> using mp_apply = mp_rename<L, F>;
 

- mp_apply<F, L> applies the function F to the contents of the list L, that is, mp_rename<F, L<T...>> + mp_apply<F, L> applies the metafunction F to the contents of the list L, that is, mp_rename<F, L<T...>> is an alias for F<T...>. (mp_apply is the same as mp_rename with the arguments @@ -973,9 +975,8 @@

mp_transform_if<P, F, L1, L2, ..., Ln> - replaces the elements T - of the list L1 for which - mp_to_bool<P<T1, T2, ..., Tn>> is mp_true + replaces the elements of the list L1 + for which mp_to_bool<P<T1, T2, ..., Tn>> is mp_true with F<T1, T2, ..., Tn>, and returns the result, where Ti are the corresponding elements of Li.

@@ -1310,7 +1311,7 @@ is the zero-based index of the first element T in L for which mp_to_bool<P<T>> is mp_true. If there is - no such element, mp_find<L, V> + no such element, mp_find_if<L, P> is mp_size<L>.

@@ -1477,7 +1478,7 @@
template<class M, class K> using mp_map_contains = mp_not<std::is_same<mp_map_find<M, K>, void>>;
 

- mp_map_contains<M, K> is mp_true, + mp_map_contains<M, K> is mp_true if the map M contains an element with a key K, mp_false otherwise. @@ -1705,7 +1706,7 @@ - +

Last revised: March 24, 2017 at 12:24:11 GMT

Last revised: March 25, 2017 at 01:01:08 GMT


diff --git a/doc/mp11/algorithm.qbk b/doc/mp11/algorithm.qbk index f03b5c4..e4a3991 100644 --- a/doc/mp11/algorithm.qbk +++ b/doc/mp11/algorithm.qbk @@ -29,7 +29,7 @@ [section `mp_transform_if`] template class P, template class F, class L...> using mp_transform_if = /*...*/; -`mp_transform_if` replaces the elements `T` of the list `L1` for which `mp_to_bool>` is `mp_true` with +`mp_transform_if` replaces the elements of the list `L1` for which `mp_to_bool>` is `mp_true` with `F`, and returns the result, where `Ti` are the corresponding elements of `Li`. [endsect] @@ -193,7 +193,7 @@ for the elements of `L` and `mp_false` for the elements of `L`. Re template class P> using mp_find_if = /*...*/; `mp_find_f` is an alias for `mp_size_t`, where `I` is the zero-based index of the first element `T` in `L` for which -`mp_to_bool>` is `mp_true`. If there is no such element, `mp_find` is `mp_size`. +`mp_to_bool>` is `mp_true`. If there is no such element, `mp_find_if` is `mp_size`. [endsect] [section `mp_reverse`] diff --git a/doc/mp11/examples.qbk b/doc/mp11/examples.qbk index ce93678..2644118 100644 --- a/doc/mp11/examples.qbk +++ b/doc/mp11/examples.qbk @@ -63,7 +63,8 @@ how we can leverage Mp11 to automate the task: using T3 = decltype( T1() + T2() ); using T4 = result; - std::cout << ( std::is_same::value? "[PASS] ": "[FAIL] " ) << name() << " + " << name() << " -> " << name() << ", result: " << name() << " " << std::endl; + std::cout << ( std::is_same::value? "[PASS] ": "[FAIL] " ) + << name() << " + " << name() << " -> " << name() << ", result: " << name() << std::endl; } int main() diff --git a/doc/mp11/list.qbk b/doc/mp11/list.qbk index 5b01b3b..4c4dcd0 100644 --- a/doc/mp11/list.qbk +++ b/doc/mp11/list.qbk @@ -88,7 +88,7 @@ is an alias for `L`. [section `mp_apply`] template class F, class L> using mp_apply = mp_rename; -`mp_apply` applies the function `F` to the contents of the list `L`, that is, `mp_rename>` is an alias for `F`. +`mp_apply` applies the metafunction `F` to the contents of the list `L`, that is, `mp_rename>` is an alias for `F`. (`mp_apply` is the same as `mp_rename` with the arguments reversed.) [endsect] diff --git a/doc/mp11/map.qbk b/doc/mp11/map.qbk index f7c1fdb..d76338b 100644 --- a/doc/mp11/map.qbk +++ b/doc/mp11/map.qbk @@ -19,7 +19,7 @@ A map is a list of lists, the inner lists having at least one element (the key.) [section `mp_map_contains`] template using mp_map_contains = mp_not, void>>; -`mp_map_contains` is `mp_true`, if the map `M` contains an element with a key `K`, `mp_false` otherwise. +`mp_map_contains` is `mp_true` if the map `M` contains an element with a key `K`, `mp_false` otherwise. [endsect] [section `mp_map_insert`] diff --git a/doc/mp11/overview.qbk b/doc/mp11/overview.qbk index 9c1389d..79502b4 100644 --- a/doc/mp11/overview.qbk +++ b/doc/mp11/overview.qbk @@ -10,8 +10,9 @@ 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]). +[@http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html Simple C++11 metaprogramming] and +[@http://pdimov.com/cpp2/simple_cxx11_metaprogramming_2.html its sequel]. Reading these +articles before proceeding with this documentation is highly recommended. The general principles upon which Mp11 is built are that algorithms and metafunctions are template aliases of the form `F` and data structures are lists of the form `L`, diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 309255c..cda0eb7 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -264,20 +264,29 @@ template using mp_iota = detail::mp_from_sequence struct mp_at_impl +template struct mp_at_c_impl; + +#if defined(BOOST_MP11_HAS_TYPE_PACK_ELEMENT) + +template class L, class... T, std::size_t I> struct mp_at_c_impl, I> { - static_assert( I::value >= 0, "mp_at: I must not be negative" ); - - using _map = mp_transform>, L>; - - using type = mp_second>>; + using type = __type_pack_element; }; +#else + +template struct mp_at_c_impl +{ + using _map = mp_transform>, L>; + using type = mp_second>>; +}; + +#endif + } // namespace detail -template using mp_at_c = typename detail::mp_at_impl>::type; - -template using mp_at = typename detail::mp_at_impl::type; +template using mp_at_c = typename detail::mp_at_c_impl::type; +template using mp_at = typename detail::mp_at_c_impl::type; // mp_take(_c) namespace detail diff --git a/include/boost/mp11/detail/config.hpp b/include/boost/mp11/detail/config.hpp index 3992cdc..75c5caa 100644 --- a/include/boost/mp11/detail/config.hpp +++ b/include/boost/mp11/detail/config.hpp @@ -29,4 +29,12 @@ # endif #endif +#if defined(__has_builtin) +# if __has_builtin(__type_pack_element) + +# define BOOST_MP11_HAS_TYPE_PACK_ELEMENT + +# endif +#endif + #endif // #ifndef BOOST_MP11_DETAIL_CONFIG_HPP_INCLUDED