RepeatedPtrField<std::string>&::iterator ?

2,602 views
Skip to first unread message

Andrew Kimpton

unread,
Apr 14, 2010, 4:15:33 PM4/14/10
to Protocol Buffers
Do I have a typo (or some other misunderstanding) or is there no support for iterators with RepeatedPtrFields ? Iterators are only available in RepeatedFields ?

google::protobuf::RepeatedPtrField<std::string>&::iterator it = message->locations().begin()

Gave me a compilation error that there was no iterator in the global namespace. Looking at the docs for RepeatedPtrField it doesn't mention iterators, and RepeatedPtrField doesn't seem to inherit from RepeatedField - the docs suggest the two objects are similar (but doesn't mention any inheritance either).

Iterating using locations().Get(index) works fine as a workaround but I was wondering if the lack of iterators was a conscious thing ?

Andrew 8-)

Jason Hsueh

unread,
Apr 14, 2010, 4:19:25 PM4/14/10
to Andrew Kimpton, Protocol Buffers
On Wed, Apr 14, 2010 at 1:15 PM, Andrew Kimpton <awki...@gmail.com> wrote:
Do I have a typo (or some other misunderstanding) or is there no support for iterators with RepeatedPtrFields ? Iterators are only available in RepeatedFields ?

google::protobuf::RepeatedPtrField<std::string>&::iterator it = message->locations().begin()

The '&' is extraneous - it's splitting up the type you want, hence the compiler is trying to find the type ::iterator.


Gave me a compilation error that there was no iterator in the global namespace. Looking at the docs for RepeatedPtrField it doesn't mention iterators, and RepeatedPtrField doesn't seem to inherit from RepeatedField - the docs suggest the two objects are similar (but doesn't mention any inheritance either).

Iterating using locations().Get(index) works fine as a workaround but I was wondering if the lack of iterators was a conscious thing ?

Andrew 8-)

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Andrew Kimpton

unread,
Apr 14, 2010, 4:36:24 PM4/14/10
to Jason Hsueh, Protocol Buffers


On Wed, Apr 14, 2010 at 4:19 PM, Jason Hsueh <jas...@google.com> wrote:


On Wed, Apr 14, 2010 at 1:15 PM, Andrew Kimpton <awki...@gmail.com> wrote:
Do I have a typo (or some other misunderstanding) or is there no support for iterators with RepeatedPtrFields ? Iterators are only available in RepeatedFields ?

google::protobuf::RepeatedPtrField<std::string>&::iterator it = message->locations().begin()

The '&' is extraneous - it's splitting up the type you want, hence the compiler is trying to find the type ::iterator.

Yep - that was it - thanks !

I'd cut-n-paste the return type from the locations() definition in the generated header to save typing and ended up with the misplaced '&'

Andrew 8-)

Reply all
Reply to author
Forward
0 new messages