Last active
May 25, 2016 00:23
-
-
Save safiire/d846a4cc0890477482aa to your computer and use it in GitHub Desktop.
Messing around with C++11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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