Skip to content

Instantly share code, notes, and snippets.

@jameskeane
Created July 9, 2011 08:30
Show Gist options
  • Save jameskeane/1073438 to your computer and use it in GitHub Desktop.
Save jameskeane/1073438 to your computer and use it in GitHub Desktop.
Static Coffeescript
#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