Boost logo

Boost :

Subject: Re: [boost] C++11 Metaprogramming
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-04-06 16:12:45


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
> outcome."

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.

An alternative would be to deduce whether it's a type or a value
depending on the context it is used in. This could be done with a GLR
parser, but I don't think any serious compiler tried to implement this.


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