Last active
December 16, 2015 11:59
-
-
Save GeorgeHahn/5431789 to your computer and use it in GitHub Desktop.
Fun with C++11
This file contains hidden or 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
| #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