Vicente J. Botet Escriba wrote:
About your mp_count example. Compare your definition with this the HOF one
template
using mp_count_if = mp_plus ;
First, you need to keep in mind that the code in the article compiled and worked at the time on the compilers that I had available, which included Visual Studio 2013. Using mp_transform was a good way to crash MSVC and remains so to this day, which is why the implementations often inline it by hand. Second, the above doesn't work because P<T>::value is allowed to be 42.
template
using mp_count = mp_cont_if >;
This - assuming that is_same_t is a template alias - cannot be made to work.
Template aliases are evaluated eagerly and is_same_t<_1, V> gives you
mp_true or mp_false depending on whether V is _1 (the literal _1) or not.
You either have to use std::is_same<_1, V> and make the algorithms take and
evaluate such lambdas by replacing placeholders and looking at ::type, or
you need to bind or curry is_same_t. mp_bind
BTW, your mp_plus doesn't take a type list as parameter.
It doesn't. There's an annoying dilemma here as most functions are useful in
either form. mp_second<L> for instance takes a list, but mp_second
About mp_contains. I've not yet finished the second article yet. IMO, we need different concepts as we can have different implementations. I believe mp_contains is an example where we can have different implementations for type list and for type set.
It does, see mp_contains and mp_set_contains in the actual mp11 source. The latter requires the elements to be unique, although the data structure is still a list. I like Lisp.
About C++11, C++14, C++17. I believe that meta-programming can profit a lot of C++17 fold expressions.
That belief is not necessarily true, but there are places where fold expressions are obviously useful, such as mp_plus. mp_fold can also be rewritten in their terms, but the performance gains are disappointingly small, although it does considerably increase the list size limit that can be handled without the compiler crashing. We'll add BOOST_NO_CXX17_FOLD_EXPRESSIONS at some point, presumably. Support is currently a bit hard to detect as Clang doesn't define an __is_feature for it. (I already had to make creative use of fold expressions to work around a Clang 3.9+ bug with mp_find.)