Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-09-18 10:33:22


From: David Abrahams <dave_at_[hidden]>
> "Jonathan Turkanis" <technews_at_[hidden]> writes:
> > "Rob Stewart" <stewart_at_[hidden]> wrote in message:
> >> From: "Jonathan Turkanis" <technews_at_[hidden]>
> >> > "David Abrahams" <dave_at_[hidden]> wrote:
> >> > > "Jonathan Turkanis" <technews_at_[hidden]> writes:
> >> >
> >> > > > template<typename Range>
> >> > > > typename range_const_iterator<X>::type
> >> > > > const_begin(Range& rng)
> >> > > > {
> >> > > > return begin(static_cast<const Range&>(rng));
> >> > > > }
> >> > >
> >> > > For one thing you can't use static_cast to change constness.
> >> >
> >> > Are you sure? The expression
> >>
> >> Yep. See 5.2.9. You'll see what static_cast can do, and then
> >> 5.2.9/3 specifically excludes any other conversions.
> >
> > The above cast seems to be permitted under 5.2.9/2, for the reason you snipped,
> > namely that
> >
> > const Range& r(rng)
> >
> > is well formed.
> >
> >> Modifying
> >> cv qualification is not among the things static_cast can do.
> >
> > Then why use the language "The static_cast operator shall not cast away
> > constness" (5.2.9/1)?
>
> I was wrong. Sorry.

So was I, it seems. You can use static_cast to *add* const.
Thanks Jonathan!

Having said that, why not use const_cast and avoid the confusion
in the first place?

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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