January 2020
Intermediate to advanced
454 pages
11h 25m
English
Example 7 demonstrates the principle of least surprise as follows:
#include <queue>#include <iostream>int main(void){ std::queue<int> my_queue; my_queue.emplace(42); std::cout << "The answer is: " << my_queue.front() << '\n'; my_queue.pop(); return 0;}
As shown in the preceding example, we are showing you how a std::queue can be used to add integers to a queue, output the queue to stdout, and remove elements from the queue. The point of this example is to highlight the fact that C++ already has a standard set of naming conventions that should be leveraged during C++ library development.
If you are designing a new library, it is helpful to the user of your library to use the same naming conventions that C++ has already defined. Doing ...