Skip to content

Instantly share code, notes, and snippets.

@safiire
Last active May 25, 2016 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safiire/d846a4cc0890477482aa to your computer and use it in GitHub Desktop.
Save safiire/d846a4cc0890477482aa to your computer and use it in GitHub Desktop.
Messing around with C++11
// C++11 is pretty neat so far.
//
// clang++ yay.cpp -o yay -std=c++11 -stdlib=libc++
#include <iostream>
#include <memory>
#include <vector>
#include <functional>
using namespace std;
class Thing {
private:
vector<int> _v{1, 2, 3, 4, 5}; // Vector initializer in the class!
public:
void each(function<void (int, int)> f){
int index = 0;
for(auto &element : _v){
f(element, index++);
}
}
};
int main(int argc, char **argv){
auto int_thing = Thing();
int_thing.each([](int element, int index) {
cout << "Element number " << index << " is " << element << endl;
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment