Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Math code snippet to add two to all elements in a container.
There are multiple ways to implement AddTwo:

Using a C++98 algorithm
Using a C++0x lambda expressions
Using a for-loop

AddTwo using an algorithm
This is the anwer of exercise #9: No for-loops #1.
#include <vector> |

Using a C++0x lambda expressions
#include <algorithm> |
AddTwo using a for-loop
Prefer algorithms over loops [1][2].
#include <vector> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.