|
Boost : |
From: Anthony Williams (anthwil_at_[hidden])
Date: 2002-08-28 02:24:26
Fernando Cacciola writes:
>
> ----- Original Message -----
> From: "Anthony Williams" <anthwil_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Tuesday, August 27, 2002 11:18 AM
> Subject: [boost] value_initialized<> uploaded to be Files Section.
>
>
> > > I've worked-around the 'operator T&() const' problem by providing a
> strict
> > > deep-constant non-member get() function, which is presented as the
> > > recommended idiom.
> >
> > If you're going to provide a non-const reference to a member of a const
> > object, that member had better be mutable....
> >
> In general, yes; but in my particular case this has a drawback:
>
> template<class T>
> struct W
> {
> operator T&() const { return x ; }
> mutable T x ;
> } ;
> W<int const> w ; // ERROR: Conflicting type modifiers: mutable const int x
> ;
OK, so you need to not specify mutable when T is const. However, leaving it
off when T is not const is undefined behaviour. Looks like a prime target for
partial specialization to me.
Anthony
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk