Created
July 9, 2011 08:30
-
-
Save jameskeane/1073438 to your computer and use it in GitHub Desktop.
Static Coffeescript
This file contains 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 <utility> | |
#include <vector> | |
#include <unordered_map> | |
#include <initializer_list> | |
using namespace std; | |
template<typename T> vector<T> StaticVector(initializer_list<T> list) { return list; } | |
template<typename T, typename Y> unordered_map<T, Y> StaticHashMap(initializer_list< pair<T, Y> > list) { | |
unordered_map<T, Y> ret; | |
for (auto it = list.begin(); it != list.end(); it++) | |
ret[(*it).first] = (*it).second; | |
return ret; | |
} | |
int main() { | |
auto number = 42; | |
auto opposite = true; | |
if(opposite) { number = -42; } | |
auto square = [&](int x) { return x * x; }; | |
auto cube = [&](int x) { return square(x) * x; }; | |
auto list = StaticVector({1, 2, 3, 4, 5}); | |
auto hash = StaticHashMap({ make_pair(1, L"Hello"), make_pair(2, L"World!") }); | |
auto cubes = [&]() { | |
auto ret = list; | |
for(int i = 0; i < list.size(); i++) { | |
ret[i] = cube(list[i]); | |
} | |
return ret; | |
}(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment