Search code examples
c++protocol-buffersprotobuf-c

Does Protocol Buffers support move constructor


I've checked the move constructor spec and a Message constructor source and didn't find one.

If there's not, does anyone know about a plan to add it?

I'm using proto3 syntax, writing a library and considering between return through value vs unique_ptr.


Solution

  • As of version 2.6.1, C++ protobuf compiler generates only copy constructors and copy assignment operators. But if your compiler supports return value optimization (and the conditions for it are satisfied) the copy constructor won't be called anyway.

    You can add some printing statements into generated code of your messages' copy constructors to see if they are really invoked or not. You can also do it by writing a protoc plugin, so it persists between protoc invocations.