Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
This is the answer of exercise #7: AddOne.
The answer is a product of the number of ways to add one to an int and the number of ways to iterate through a std::vector.
The number of ways to add one to an int are five:
The number of ways to iterate through a std::vector are twelve:
This makes the number of ways to do this sixty!
There are two more:
Total: there are sixty-two ways to add one to each element in a std::vector!
P.S. an additional way (though beyond this exercise) is to use assembler.
This kind of program is called a benchmark.
There are too many ways to write one, so I'll just show you mine, which can be found at the cpp_benchmark_add_one GitHub. There you will find the benchmark results in the Travis CI scripts.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.