The code in question used to use google::protobuf::NewCallback<>. I need to be able to promote a weak_ptr within Run() so I can't use it as is. I don't want to change any Protobuf related code hence SelfDeletingCallback.
> And as Alexandros says, callbacks could throw.
OK.
> 20 +class SelfDeletingCal lback : public google: :protobuf: :Closure { lback(std: :function< void()> const& callback) lback(SelfDelet ingCallback& ) = delete; lback&) = delete; void()> callback; :protobuf: :NewCallback< > deletes itself. llback< > is the version that doesn't).
> 21 +public:
> 22 +
> 23 + SelfDeletingCal
> 24 + : callback(callback)
> 25 + {
> 26 + }
> 27 +
> 28 + void Run() {
> 29 + callback();
> 30 + delete this;
> 31 + }
> 32 +
> 33 + private:
> 34 + SelfDeletingCal
> 35 + void operator=(const SelfDeletingCal
> 36 + std::function<
> 37 +};
>
> Why is this needed? google:
> (NewPermanentCa
The code in question used to use google: :protobuf: :NewCallback< >. I need to be able to promote a weak_ptr within Run() so I can't use it as is. I don't want to change any Protobuf related code hence SelfDeletingCal lback.
> And as Alexandros says, callbacks could throw.
OK.