[hana] some notes, not a review
Dear All, I have just a couple of notes about Hana; this does not constitute a review: Firstly, as I understand it Hana believes that it can replace much or all of what Fusion and MPL provide with a superior alternative. If that is the case, I suggest that the docs should not start out by describing Hana with reference to those libraries. At present, it would seem that in order to understand what Hana can do for me, I need to first learn at least a little about those other libraries - and then the Hana docs tell me how it compares to them. This might not be a bad thing in the context of docs for this review, but for "end user" documentation it should stand alone. Secondly, we're moving towards a future where a lot of what previously required TMP can now be done using "regular" C++ code qualified with constexpr. I've just replaced a fair chunk of my crufty old TMP code with constexpr and it is like a breath of fresh air. Against that background, it might be worthwhile to structure your examples by showing what Hana (and TMP in general, perhaps) can do that constexpr cannot do, i.e. start with an example using constexpr and extend it to add features not possible with constexpr. Regards, Phil.
Phil Endecott
Dear All,
I have just a couple of notes about Hana; this does not constitute a review:
Firstly, as I understand it Hana believes that it can replace much or all of what Fusion and MPL provide with a superior alternative. If that is the case, I suggest that the docs should not start out by describing Hana with reference to those libraries. At present, it would seem that in order to understand what Hana can do for me, I need to first learn at least a little about those other libraries - and then the Hana docs tell me how it compares to them. This might not be a bad thing in the context of docs for this review, but for "end user" documentation it should stand alone.
I agree that the documentation _could_ be more self-contained. However, I am not sure it _should_ be. Indeed, I am OK with offloading some of the explanation about "what is template metaprogramming" to other resources, since the tutorial would otherwise double in size. When looking at Fusion's documentation, for example, they cite MPL to introduce their own work. And for the MPL, they wrote a book to explain "what is C++ template metaprogramming". So, while you are definitely correct that Hana's tutorial is not self- contained, I will not take direct actions to change this unless at least a couple of persons express this desire, since that's a lot of work (and not especially pleasant work either).
Secondly, we're moving towards a future where a lot of what previously required TMP can now be done using "regular" C++ code qualified with constexpr. I've just replaced a fair chunk of my crufty old TMP code with constexpr and it is like a breath of fresh air. Against that background, it might be worthwhile to structure your examples by showing what Hana (and TMP in general, perhaps) can do that constexpr cannot do, i.e. start with an example using constexpr and extend it to add features not possible with constexpr.
I guess it really depends on what kind of TMP code that was. Type-level computations and heterogeneous computations (like Fusion) are not impacted by constexpr. This distinction is partly what I wanted to make in the introduction (the quadrants of computation), but it seems like I could show clearer examples of where homogeneous constexpr computations differ from heterogeneous computations. Is this distinction (between homogeneous-constexpr computations and heterogeneous computations) what you would like to see exposed more clearly? Thanks for your comments, Louis
On 18/06/2015 16:50, Phil Endecott wrote:
Secondly, we're moving towards a future where a lot of what previously required TMP can now be done using "regular" C++ code qualified with constexpr. I've just replaced a fair chunk of my crufty old TMP code with constexpr and it is like a breath of fresh air. Against that background, it might be worthwhile to structure your examples by showing what Hana (and TMP in general, perhaps) can do that constexpr cannot do, i.e. start with an example using constexpr and extend it to add features not possible with constexpr.
What template meta-programming were you able to replace by constexpr? As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
On 6/19/15 1:40 AM, Mathias Gaunard wrote:
What template meta-programming were you able to replace by constexpr?
As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
Hmmm - what about all the mpl arithmetic functions built around mpl integral constants? All that gets replace by easy to understand compile time expressions which can be used in other template expressions? This simplifies things immensely. Robert Ramey
Robert Ramey
On 6/19/15 1:40 AM, Mathias Gaunard wrote:
What template meta-programming were you able to replace by constexpr?
As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
Hmmm - what about all the mpl arithmetic functions built around mpl integral constants? All that gets replace by easy to understand compile time expressions which can be used in other template expressions? This simplifies things immensely.
As far as my current experience goes, this is one of the only use cases where constexpr can help (but it does help a lot in that case). You can replace complex arithmetic with equivalent constexpr code and it's going to be much simpler to read and also more efficient at compile-time. It's also possible to use constexpr to do some index calculations as an implementation detail of an heterogeneous algorithm. For example, to compute the cartesian product of tuples, I actually generate the proper sequence of indices using constexpr computations, and then index the sequences with these indices, getting back a tuple of tuples. But that's hardly useful outside of deep TMP algorithms. Louis
On 6/19/15 1:40 AM, Mathias Gaunard wrote:
What template meta-programming were you able to replace by constexpr?
As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
In http://pdimov.com/cpp2/simple_cxx11_metaprogramming_2.html I show one constexpr use that isn't an optimization hint. It involves traversing a constexpr array of bools at compile time.
On Fri, Jun 19, 2015 at 2:40 AM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
What template meta-programming were you able to replace by constexpr?
As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
All of the calculation for new bounds of my bounded::integer library use constexpr computation. The result of these constexpr computations will be used as template parameters (so the value computations in my constexpr functions will be used to determine a template type). The entire contents of https://bitbucket.org/davidstone/bounded_integer/src/51e8369077e4765136e0718... show this, especially https://bitbucket.org/davidstone/bounded_integer/src/51e8369077e4765136e0718... What I am currently working on with this will make it especially difficult to replace this with non-type template parameters for a more C++03 metaprogramming style, because the template parameters to my constexpr functions will themselves be bounded::integer types, which are not allowed as non-type template parameters.
participants (6)
-
David Stone
-
Louis Dionne
-
Mathias Gaunard
-
Peter Dimov
-
Phil Endecott
-
Robert Ramey