
on Thu Apr 05 2012, Andrzej Krzemienski <akrzemi1-AT-gmail.com> wrote:
For the end users of meta-programming library (at least those interested in type transformations), I believe that alias templates offer a significant improvement to the interface: http://akrzemi1.wordpress.com/2012/03/19/meta-functions-in-c11/
Yeah... I started doing a bunch of that, but I am not yet convinced it's an overall improvement. One thing you emphatically *don't* get with that formulation is lazy evaluation. remove_pointer<int> is valid until you instantiate it but RemovePointer<int> is not, and the former is often quite useful. Also, you can't use metafunction forwarding—which also eliminates vast amounts of typing—with RemovePointer. Also, you end up needing to define more names than you otherwise would (e.g. both remove_pointer and RemovePointer). My standard approach when doing this has been to name them remove_pointer_ and remove_pointer, so at least they have an obvious and mechanical relationship.
I guess my understanding of the name "meta-programming" might be a bit different, and term "end user" might have been too much a mental shortcut, but let me share my view of someone that doesn't want to go to deep into the meta-programming but still needs to use the simple forms thereof (like type traits). This is a somewhat simplified version of what I was facing recently. I need a function that perfect-forwards the argument but returns by value: template <class T> T fun(T&& v); The above is incorrect, because T may be deduced to be an lvalue reference. But be sympathetic, perfect-forwarding is already hard enough to acquire. I need type trait std::decay: template <class T> std::decay<T> fun(T&& v); But this does not work! I forgot "::type". Let's try again: template <class T> std::decay<T>::type fun(T&& v); No. It still doesn't work. And this is the worst part: I forgot the "typename". Having to type this "typename" is really terrible and just scares off many people. If you do not mind it, it only means that you got used to it; but people should not be forced to get used to too many gotchas. Alias templates offer a simplification that can improve the "teachability" of type traits. You may not consider type traits a proper meta-programming, and all I say might be a bit off topic. But if we had these alias templates for type traits, it looks to me, it would make a soft introduction to meta-programming for the newbies. Regards, &rzej

On 06/04/12 09:04, Andrzej Krzemienski wrote:
And this is the worst part: I forgot the "typename". Having to type this "typename" is really terrible and just scares off many people. If you do not mind it, it only means that you got used to it; but people should not be forced to get used to too many gotchas.
The language requires to specify whenever dependent names in template contexts are anything else than values (i.e. types or templates). There is no substitute for learning the basics of the language. This is not a gotcha, just normal usage of templates.

on Fri Apr 06 2012, Mathias Gaunard <mathias.gaunard-AT-ens-lyon.org> wrote:
On 06/04/12 09:04, Andrzej Krzemienski wrote:
And this is the worst part: I forgot the "typename". Having to type this "typename" is really terrible and just scares off many people. If you do not mind it, it only means that you got used to it; but people should not be forced to get used to too many gotchas.
The language requires to specify whenever dependent names in template contexts are anything else than values (i.e. types or templates).
There is no substitute for learning the basics of the language. This is not a gotcha, just normal usage of templates.
While true, I agree with Andrzej that it is a shame and it would be better to smooth this sort of thing over for users. It's just a question of whether we give up too much valuable power for anyone wanting to go beyond the most basic usage by doing so. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (3)
-
Andrzej Krzemienski
-
Dave Abrahams
-
Mathias Gaunard