Skip to content

Instantly share code, notes, and snippets.

@cbsmith
Created May 21, 2013 16:41
Show Gist options
  • Save cbsmith/5621276 to your computer and use it in GitHub Desktop.
Save cbsmith/5621276 to your computer and use it in GitHub Desktop.
Demonstration of how two_star programming works with STL containers and algorithms.d
// -*- compile-command: "clang++ -ggdb -o two_stars -std=c++0x -stdlib=libc++ two_stars.cpp" -*-
#include <algorithm>
#include <iostream>
using namespace std; //laziness
int main(int argc, char** argv) {
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 2;
int* two_star_container[] = { &a, &b, &c, &d, &e };
for (auto i = begin(two_star_container); i != end(two_star_container); ++i) {
cout << **i << endl;
}
auto new_end = remove_if(begin(two_star_container), end(two_star_container), [](int* val) { return (*val) == 2; });
cout << "Removed the 2's" << endl;
for (auto i = begin(two_star_container); i != new_end; ++i) {
cout << **i << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment