Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-07-26 16:40:51


tim_at_[hidden] wrote:
>
> --- In boost_at_y..., Daryle Walker <darylew_at_m...> wrote:
> > I don't think you realize that not
> > all types support the pre-qualifier form!
>
> You are right. I won't try to describe the parsing
> contortions my mind goes through mapping post-qualifiers
> on pointers into a pre-qualifier world.

        I think you're having the same trouble
the committee did. The rule is that 'const' is always
associated with the pointer NOT the type: there is
no such type as 'const int'. There is no 'pointer to
a const int' either. What exists in reality is
a pointer-const to int:

        int const*

where I put lots of white space to indicate what's
connected to what. Don't get confused like the committee
did with

        int const x = 1;

x is NOT a const int type. Its a ref-const to int:

        int const& x = 1;

See? x has the SAME type in both cases.
Or consider:

        void f(int);
        void g(const int);

See? f and g have the SAME type in both cases.

Its the ref or pointer which is qualified, NOT the
object type. If there's no pointer or reference,
cv-qualifiers are meaningless.

So the reason you write the const AFTER the type is
that you must put the word 'const' next to the thing
that it _actually_ qualifies, the * or & or implied &.
Putting it before the type as in:

        const int *

is obviously very bad practice because the suggestion
is just NOT how the type system really works.
But you're in good company, even Bjarne got this wrong.

-- 
John (Max) Skaller, mailto:skaller_at_[hidden] 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix  http://felix.sourceforge.net
Literate Programming tool Interscript     
http://Interscript.sourceforge.net

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