|
Boost Users : |
Subject: Re: [Boost-users] Serialization with pointer to const object
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-07-24 19:32:18
On Fri, Jul 24, 2009 at 4:40 PM, Robert Ramey<ramey_at_[hidden]> wrote:
>
> Emil Dotchevski wrote:
>> IMO even after the serialization library dereferences the
>> pointer-to-const, it should const_cast it to serialize the object,
>> because in the typical case the object is mutable. For example, if you
>> have:
>>
>> int const * p=new int(42);
>
> So p->member of p should fail to compiler while ar << p should?
>
> Doesn't make sense to me. I think it's a very bad idea to try to
> make things "just work" when it means changing the behavior from
> what is written to what one would think is a " rather safe bet".
Probably the reason why it doesn't make sense to you but it makes
sense to me is that you're looking at serializing a pointer as a
mutable operation on the pointee, whereas I look at it as a mutable
operation on the pointer itself.
Please don't get me wrong, I wouldn't want the following code to compile:
struct foo
{
int const m_x;
};
....
ar << a_foo.m_x;
But I think that the code below should just work:
struct foo
{
int const * m_x;
};
....
ar << a_foo.m_x;
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
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