Skip to content

Instantly share code, notes, and snippets.

@asa55
Created April 3, 2020 22:12
Show Gist options
  • Save asa55/521e26d8ef5d13b130a0e28896d970fe to your computer and use it in GitHub Desktop.
Save asa55/521e26d8ef5d13b130a0e28896d970fe to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
void Print(int s)
{
std::cout << s << std::endl;
}
void ForEach(const std::vector<int>& values, void(*func)(int))
{
for(int value : values) // this is called a range-based for loop, and I love it! // https://www.cprogramming.com/c++11/c++11-ranged-for-loop.html
func(value);
}
int main()
{
std::vector<int> values = { 1, 2, 3, 4, 5, 6, 7, 8 };
auto myfun = Print;
ForEach(values, myfun);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment