Professional C__ - Marc Gregoire [200]
// Selects the next process using a round-robin scheduling
// algorithm and allows it to perform some work during
// this time slice.
void scheduleTimeSlice();
// Removes the given process from the list of processes.
void removeProcess(const Process& process);
protected:
RoundRobin }; Scheduler::Scheduler(const vector { // Add the processes for (auto& process : processes) { rr.add(process); } } void Scheduler::scheduleTimeSlice() { try { rr.getNext().doWorkDuringTimeSlice(); } catch (const out_of_range&) { cerr << "No more processes to schedule." << endl; } } void Scheduler::removeProcess(const Process& process) { rr.remove(process); } int main() { vector Scheduler sched(processes); for (int i = 0; i < 4; ++i) sched.scheduleTimeSlice(); sched.removeProcess(processes[1]); cout << "Removed second process" << endl; for (int i = 0; i < 4; ++i) sched.scheduleTimeSlice(); return 0; } Code snippet from RoundRobin\RoundRobinTest.cpp The output should be as follows. Process 1 performing work during time slice. Process 2 performing work during time slice. Process 3 performing work during time slice. Process 1 performing work during time slice. Removed second process Process 3 performing work during time slice. Process 1 performing work during time slice. Process 3 performing work during time slice. Process 1 performing work during time slice. The vector The standard requires a partial specialization of vector for bools, with the intention that it optimizes space allocation by “packing” the Boolean values. Recall that a bool is either true or false, and thus could be represented by a single bit, which can take on exactly two values. C++ does not have a native type that stores exactly one bit. Some compilers represent a Boolean value with a type the same size as a char. Some other compilers use an int. The vector You can think of the vector In a half-hearted attempt to provide some bit-field routines for the vector At this point, you should be wondering how you can call a method on a reference to bool. The answer is that you can’t. The vector The fact that references returned from vector In practice, the little amount of space saved by packing bools hardly seems worth the extra effort. However, you should be familiar with this partial instantiation because of the additional flip() method, and because of the fact that references are actually proxy objects. Many C++ experts recommend avoiding vector deque The deque (abbreviation for double-ended queue) is almost identical to the vector, but is used far less frequently. It is defined in the The implementation is not required to store elements contiguously in memory. The deque supports constant-time