Boost logo

Boost :

Subject: Re: [boost] [review][mp11] Formal review of Mp11
From: Fletcher, John P (j.p.fletcher_at_[hidden])
Date: 2017-07-17 15:05:13


I am interested in MP11 and will submit a review before the end of the review period. I want to make some comments in advance of this on some topics which I have not seen discussed already. These particularly relate to mp_quote_trait which I am finding very useful to adapt old C++03 code. In my initial work using MP11 I found that the examples given in the documentation contained some features which are not C++11 but instead C++14 or later. As I am wanting to adapt code from C++03 it is not helpful to have things which do not compile with C++11 only. I am particularly interested in code which works out return types for functions where the application can be polymorphic. The origins of much of this code are quite old now, originating with FC++ although there are more modern versions in Boost Phoenix. See for example http://www.boost.org/doc/libs/1_64_0/libs/phoenix/doc/html/phoenix/lazy_list/background.html One item in MP11 which I have found useful is mp_quote_trait. This seems to be a late addition to the code as it was not in the first version of the code I downloaded. One thing which was not clear to me in the documentation was how to use the resulting object. I looked for things with “q” in the name. The answer to this is mp_invoke which does not have a “q”. Example: using mp_q_common_type_t = mp_quote_trait<std::common_type>; template <class... T> using result_q_t = mp_invoke<mp_q_common_type_t, T...>; This is very helpful as the resulting code works with C++11 avoiding the need to define common_type_t which is only introduced in C++14. I have also used the following extensions to MP11 invented to handle case where the struct to be quoted has int N at start o the list of types. template<template<int, class...> class F> struct mp_quote_trait_N { template<int N, class... TN> using fn = typename F<N, TN...>::type; }; template<class Q, int N, class... TN> using mp_invoke_N = typename Q::template fn<N,TN...>; One application if this is the specialization the result type from a function FF with different numbers of arguments. using mp_q_result_of_t = mp_quote_trait<boost::result_of>; template <int N, typename FF, typename... XYZ> struct RTHelper; template <typename FF,typename A> struct RTHelper <1,FF,A> { typedef mp_invoke<mp_q_result_of_t,F(A)> type; }; and for N=2, 3 etc. I hope this is helpful Best wishes John Fletcher


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk