Re: [protobuf] Why doesn't protobuf C++ include smart pointers to submessages?

2017-07-24 Thread Alex Shaver
The std::weak_ptr does need a shared_ptr, but that doesn't necessarily prevent them from creating their own 'weak_reference' class or whatever that could check on whether what it pointed to was still valid or not. The case I'm using it for is I have a top level message, with a repeated set of

Re: [protobuf] Why doesn't protobuf C++ include smart pointers to submessages?

2017-07-24 Thread Arpit Baldeva
A weak_ptr needs a shared_ptr to begin with so all the submessages would end up being a shared_ptr (creating an impression that they are meant for shared ownership). In fact, I feel that Protobuf could perhaps change the generated code to use unique_ptr instead of it's raw pointers to more

Re: [protobuf] Why doesn't protobuf C++ include smart pointers to submessages?

2017-07-21 Thread Alex Shaver
I agree that since the model is that the top message owns its submessages, the idea of shared ownership isn't necessarily useful. But something like a weak pointer doesn't change the ownership, it would just allow objects to be responsive to whether the submessage exists or not. While holding

Re: [protobuf] Why doesn't protobuf C++ include smart pointers to submessages?

2017-07-21 Thread 'Adam Cozzette' via Protocol Buffers
I think this would be a pretty difficult and invasive change to make, because the basic memory model used by C++ protobuf is that each message has sole ownership of its submessages, with no notion of shared ownership. If we did introduce a change like this, it would also force existing users to