const Population = struct {
// element 0 is the teacher
// elements 1... are the students
people: []Person,
const teacher_index = 0;
const first_student_index = 1;
pub fn teacher(self: Population) *Person {
return &self.people[teacher_index];
}
pub fn students(self: Population) []Person {
return self.people[first_student_index..];
}
}
Could also use enum(usize) { teacher = 0, _ }; for the indexes if you want type safety, but I’m not sure how beneficial that’d be for this use case. See here for an example of that sort of thing.