|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-02-16 11:38:20
Ian McCulloch <ianmcc_at_[hidden]> writes:
> Chris Goller wrote:
>
>> David-
>>
>> First, thanks for the response. BTW, I really like the book.
>>
>> Okay, I understand what you are saying about add_const and how it works.
>>
>> My next question is why was it implemented in that way? In other words,
>> was there a specific reason not to make a special case
>> for references such that add_const<int&> would be int const &?
>
> FWIW, you will soon be able to get that effect without a metafunction.
> from http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#106
> [example]
> int i;
> typedef int& RI;
> RI& r = i; // r has the type int&
> const RI& r = i; // r has the type const int&
> [/example]
>
> I'm not sure I like it, because a 'RI const' is 'int&', but a reference to a
> 'RI const' is 'int const&'. But maybe its useful that way.
Oh, that's very disturbing. What is the rationale for moving the
const inside the reference?
Ah, I see it in N1245:
template<class T> class X { f(const T&) ; /* ... */ };
X<int&> x; // X<int&>::f has the argument type const int&
I'm not convinced that special rule is worth the breath and text
needed to explain it. With any well-behaved class X, if f was written
to work on a "const X&" argument, it will work equally well and
correctly on a "X&" argument.
It's probably too late for objections now, though.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net