Skip to content

Instantly share code, notes, and snippets.

@cbsmith
Created May 21, 2013 17:09
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 cbsmith/5621454 to your computer and use it in GitHub Desktop.
Save cbsmith/5621454 to your computer and use it in GitHub Desktop.
C++98 version of two_stars
// -*- compile-command: "clang++ -ggdb -o two_stars_98 -std=c++98 -stdlib=libc++ two_stars_98.cpp" -*-
#include <algorithm>
#include <iostream>
using namespace std;
bool points_to_two(int* x) {
return *x == 2;
}
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 };
int** start = two_star_container;
int** end = &two_star_container[6];
for (int** i = start; i != end; ++i) {
cout << **i << endl;
}
int** new_end = remove_if(start, end, points_to_two);
cout << "Removed the 2's" << endl;
for (int** i = start; 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