Skip to content

Instantly share code, notes, and snippets.

@GeorgeHahn
Last active December 16, 2015 11:59
Show Gist options
  • Select an option

  • Save GeorgeHahn/5431789 to your computer and use it in GitHub Desktop.

Select an option

Save GeorgeHahn/5431789 to your computer and use it in GitHub Desktop.
Fun with C++11
#include <string>
#include <functional>
#include <stdio.h>
using namespace std;
// Need to create one class each to pass in and out
typedef int (*fp)(int);
class RouteyThingy
{
public:
fp fpi;
fp& operator[] (const string& str)
{
printf("Assigned something to the path '%s'\n", &str);
return fpi;
}
void runit()
{
int response = (*fpi)(1);
printf("view responded with a %d\n", response);
}
};
#define is = [](int dat) -> int
RouteyThingy GET;
extern "C" void DOME()
{
GET["/"] is {
printf("Hi! You passed me a nice %x\n", dat);
return 0;
};
GET.runit(); // To show it can do stuff
GET["/index/"] is {
printf("See! %x\n", dat);
return 42;
};
GET.runit(); // Do
GET["/home/"] is {
printf("Hola\n");
return 0;
};
GET.runit(); // More doing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment