Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Container code snippet to triple all values in a container.
There are multiple ways to perform Triple:

The general algorithm way using std::bind2nd
The general algorithm way using BOOST_FOREACH
The general algorithm way using boost::lambda
The C++98 algorithm way on a std::vector<int>
Using a C++0x lambda expressions on a std::vector<int>
The for-loop way on a std::vector<int>

The general algorithm way using std::bind2nd
#include <algorithm> |

The general algorithm way using BOOST_FOREACH
#include <boost/foreach.hpp> |

The general algorithm way using boost::lambda
#include <algorithm> |

The C++98 algorithm way on a std::vector<int>
This version is given as the answer of Exercise #9: No for-loops.
#include <vector> |

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