
From: David Abrahams <dave@boost-consulting.com>
"Jonathan Turkanis" <technews@kangaroologic.com> writes:
"Rob Stewart" <stewart@sig.com> wrote in message:
From: "Jonathan Turkanis" <technews@kangaroologic.com>
"David Abrahams" <dave@boost-consulting.com> wrote:
"Jonathan Turkanis" <technews@kangaroologic.com> 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@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;