gpt4 book ai didi

c++ - 如何删除重复字段中的任意对象? (protobuf)

转载 作者:IT老高 更新时间:2023-10-28 22:10:10 47 4
gpt4 key购买 nike

我在原型(prototype)的重复字段中有一些条目。现在我想删除其中的一些。我怎样才能做到这一点?有删除最后一个元素的功能,但我想删除任意元素。我不能只是交换它们,因为顺序很重要。

我可以与 next 交换直到结束,但没有更好的解决方案吗?

最佳答案

对于 Protobuf v3

iterator RepeatedField::erase(const_iterator position)可以在任意位置删除。

对于 Protobuf v2

您可以使用 DeleteSubrange(int start, int num)RepeatedPtrField 类中。

如果要删除单个元素,则必须将此方法称为 DeleteSubrange(index_to_be_del, 1)。它将删除该索引处的元素。

关于c++ - 如何删除重复字段中的任意对象? (protobuf),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13603878/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com