You can write a customize sort functor when using the stl, which sort the
index of the students, like:struct SortStudent : public
binnary_function<bool, int, int> {
  SortStudent(Class *cl) : cl_(cl) {
  }
  bool operator() (int i, int j) {
   int32 score1 = cl_->student(i).score();
   int32 score2 = cl_->student(j).score();
   return score1 < score2;
  }
  Class *cl_;
};

Class *cl; // Where you can get the Class instance.
int num_student = cl->student_size();
vector<int> student_indice;
for (int i = 0; i < num_student; ++i) {
  student_indice.push_back(i);
}
sort(student_indice.begin(), student_indice.end(), SortStudent(cl));

2009/7/29 李海波 <lihaibo2...@gmail.com>

>
> example:
> ==========.proto file ============
> message Class{
>    message Student{
>        required string name = 1;
>        required int32 score  = 2;
>    }
>
>    repeated Student student = 1;
> }
> =============================
>
> I want to sort students of the class by score,how can i do?
> >
>

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

Reply via email to