Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-03-15 23:36:18


----- Original Message -----
From: "rwgk" <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, March 15, 2002 3:12 PM
Subject: [boost] Re: transitive_const?

> --- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> > This is a familiar issue. I have two proposals for you:
> >
> > 1. specialize for T const and cast away const-ness in the general
> > template:
> >
> > template <class T>
> > struct ref : ref<T const>
> > {
> > T* begin() { const_cast<T*>(this->ref<T const>::begin()); }
> > };
> >
> > template <class T>
> > struct ref<T const>
> > {
> > ...
> > };
>
> Wow, I didn't think you could inherit from a partial
> specialization of yourself ... ("inherit" does not even
> sound appropriate, this is more "preherit")
>
> > 2. Check out how const/non-const iterator interactions are handled
> > (differently) in the iterator adaptors lib. You can read about it
> > in the paper at www.boost.org/libs/utility/iterator_adaptors.pdf
>
> Does this approach also involve partial specialization (or any
> other language feature not supported by the most beloved VC6
> compiler)?

No, but you can do the other one without partial spec, provided you do a
bunch more work:

template <class T> struct const_ref { ... };
template <class T> struct non_const_ref : const_ref<T> { ... };

template <class T>
struct ref
    : mpl::select_type<
        is_const<T>::value
        , const_ref<T>
        , non_const_ref<T>
>::type
{};

> I am still curious: have there been discussions about
> introducing direct support for something like "transitive_const"
> into the language?

I still don't know what "transitive const" means.

> -- When I first saw types like "const_iterator"
> I was very puzzled. And then, what is "const const_iterator?"

Analogous to T const*const. You can't iterate it or assign to it.

> Wouldn't transitive_const make strange looking types like this
> obsolete?

I guess it depends what transitive_const is...

-Dave


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