How to convert a RepeatedField<google::protobuf::uint32>
to a const std::vector<double>
?
Asked
Active
Viewed 9,796 times
4
-
Removing each element from RepeatedField and putting it in the vector should work. – Galik Nov 28 '14 at 13:55
-
@BenjaminBannier: All (u)int32 values can be stored precisely in a double. http://stackoverflow.com/a/1848762/25488 – RobH Nov 28 '14 at 14:09
1 Answers
15
That should be easy, since repeated fields act as containers:
void foo(RepeatedField<google::protobuf::uint32> const & f)
{
std::vector<double> v(f.begin(), f.end());
// use v
}

Kerrek SB
- 464,522
- 92
- 875
- 1,084
-
1
-
I am getting this error "expression vector iterator + offset out of range" – Dosti Nov 28 '14 at 14:15
-
Yes... it is executing fine, but at one point it is throwing this error. – Dosti Nov 28 '14 at 14:20
-
@Dosti: Then you have a mistake elsewhere, not fundamentally connected with the iterator interface of `RepeatedField`. – Kerrek SB Nov 28 '14 at 14:24