C++11 for each loops with RepeatedField

6,884 views
Skip to first unread message

Justin

unread,
Apr 18, 2014, 2:28:51 PM4/18/14
to prot...@googlegroups.com
I assume there is a simple answer to this, but I'm having trouble finding it and my searches for similar questions have come up empty ... Perhaps it being Friday afternoon is also reducing my ability to solve this :)

I want to be able to use C++11 range-based for loops on a repeated field in my message, but I can't seem to get it to compile properly. This is true for mutable and const references.

So, for example:

for (message_item &curr_message : data.mutable_message_item())

does not work, nor can I do so without the mutable, but I would think it should. 

Is this because RepeatedField does not support the appropriate operators?




Feng Xiao

unread,
Apr 18, 2014, 2:40:14 PM4/18/14
to Justin, Protocol Buffers
On Fri, Apr 18, 2014 at 11:28 AM, Justin <jsca...@gmail.com> wrote:
I assume there is a simple answer to this, but I'm having trouble finding it and my searches for similar questions have come up empty ... Perhaps it being Friday afternoon is also reducing my ability to solve this :)

I want to be able to use C++11 range-based for loops on a repeated field in my message, but I can't seem to get it to compile properly. This is true for mutable and const references.

So, for example:

for (message_item &curr_message : data.mutable_message_item())
Try: 
for (message_item &curr_message : *data.mutable_message_item())


does not work, nor can I do so without the mutable, but I would think it should. 

Is this because RepeatedField does not support the appropriate operators?




--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Justin

unread,
Apr 18, 2014, 2:45:00 PM4/18/14
to prot...@googlegroups.com, Justin
Thanks! I knew it was going to be something simple ... I blame end of week exhaustion!
Reply all
Reply to author
Forward
0 new messages