Subject: Re: [boost] C++11 Metaprogramming
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-07 11:08:38
on Fri Apr 06 2012, Mathias Gaunard <mathias.gaunard-AT-ens-lyon.org> wrote:
> On 06/04/12 12:26, Andrzej Krzemienski wrote:
>> But looking at it from the fresh programmer's perspective, the fact that
>> the language requires "to specify whenever dependent names in template
>> contexts are anything else than values" means that the language is not
>> friendly to the fresh programmers (I understand that there are good reasons
>> for requiring this, but still...).
>> Based on the Wkipedia's definition of "gotcha" I interpret this typename as
>> one. "In programming, a gotcha is a feature of a system, a program or a
>> programming language that works in the way it is documented but is
>> counter-intuitive and almost invites mistakes because it is both enticingly
>> easy to invoke and completely unexpected and/or unreasonable in its
> When a compiler encounters a function or class template, it builds a
> parametric AST. Without knowing what the parameters are, it cannot
> know what the names that depend on the parameters are, and thus what
> kind of AST to generate; indeed C++, unlike other programming
> languages, makes it ambiguous what kind of entity a name refers to.
> Some compilers do not require this because they do not build a real
> AST when parsing a template. As a result they have a lot of bugs,
> especially in name lookup.
I think Andrzej understands very well the reasons for "typename" and the
consequences of failing to implement 2-phase name lookup. IIUC he's
just saying (correctly) that such understanding does not come
easily---even many very experienced C++ programmers don't have it---and
the current situation is hard for many programmers to deal with.
> An alternative would be to deduce whether it's a type or a value
> depending on the context it is used in.
...which is in some cases impossible. My book has examples of code that
could be valid either way.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk