Skip to content

Instantly share code, notes, and snippets.

@phg1024
Created September 19, 2017 23:43
Show Gist options
  • Save phg1024/12e77e4e6dd0b2535055f112da620d6b to your computer and use it in GitHub Desktop.
Save phg1024/12e77e4e6dd0b2535055f112da620d6b to your computer and use it in GitHub Desktop.
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
using namespace std;
int f(int argc, char* argv[]) {
for(int i=0;i<argc;++i) cout << argv[i] << endl;
return 0;
}
int main(int argc, char** argv) {
auto run_with_args = [](const std::function<int(int, char*[])> func, const vector<string>& args_in) {
char** args = new char*[args_in.size()];
for(int i=0;i<args_in.size();++i) {
args[i] = new char[args_in[i].size() + 1];
strcpy(args[i], args_in[i].data());
}
bool succeeded = (func(args_in.size(), args) == 0);
for(int i=0;i<args_in.size();++i) delete[] args[i];
delete[] args;
return succeeded;
};
run_with_args(f, vector<string>{"a", "b", "c"});
run_with_args(f, vector<string>{"axxxxx", "x--b", "---c", "35"});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment