Skip to content

Instantly share code, notes, and snippets.

View rmartinho's full-sized avatar

R. Martinho Fernandes rmartinho

View GitHub Profile
@rmartinho
rmartinho / stack_alloc.h++
Created April 17, 2013 15:42
Just a sample of what kind of magic I think could make a C++ alloca().
// Usage:
// int f(int n) {
// auto buf = stack_alloc<int>(n);
// std::iota(buf.begin(), buf.end());
// return std::sum(buf.begin(), buf.end());
// }
// allocation function
template <typename T>
stack_array_ref<T> stack_alloc(size_t size) __magic_works_like_a_macro_to_use_the_right_frame__;
@rmartinho
rmartinho / fast.c++
Last active December 16, 2015 02:39
“I want it as fast as possible”
int main(){}
$ locale
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
@rmartinho
rmartinho / flavoured_strings.cpp
Created March 23, 2013 13:50
Using char_traits to get strong string aliases.
#include <string>
#include <iostream>
namespace dessert {
template <typename Tag>
struct not_quite_the_same_traits : std::char_traits<char> {};
template <typename Tag>
using strong_string_alias = std::basic_string<char, not_quite_the_same_traits<Tag>>;
using vanilla_string = std::string;
@rmartinho
rmartinho / 01broken_vector.cpp
Last active December 15, 2015 07:09
Never pass vectors by reference. Wait, never pass ints by reference. Better, never pass anything by reference.
struct Gadget
{
std::vector<Widget> w;
};
void thread1()
{
Gadget g;
launch_async(unsafe(g.w));
" Sets up multi-language syntax for Jekyll blog posts
fun! SetJekyllPostSyntax()
" Bring in YAML syntax for front matter
unlet b:current_syntax
syntax include @Yaml syntax/yaml.vim
syntax region yamlFrontmatter start=/\%^---$/ end=/^---$/ keepend contains=@Yaml
" Bring in C++11 syntax for code snippets
unlet b:current_syntax
syntax include @Cpp syntax/cpp11.vim
@rmartinho
rmartinho / arrays.h
Last active October 12, 2015 02:48
Simple functions for better usage of arrays
// begin() and end() functions for arrays (C++03)
//
// Written in 2012 by Martinho Fernandes
//
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this software to the public domain worldwide. This software is
// distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
@rmartinho
rmartinho / darray2d.h
Created October 26, 2012 17:05
Two-dimensional array with dimensions determined at runtime
// Two-dimensional array with dimensions determined at runtime
//
// Written in 2012 by Martinho Fernandes
//
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this software to the public domain worldwide. This software is
// distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
@rmartinho
rmartinho / sarray2d.h
Created October 26, 2012 17:04
Two-dimensional array with dimensions determined at compile-time
// Two-dimensional array with dimensions determined at compile-time
//
// Written in 2012 by Martinho Fernandes
//
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this software to the public domain worldwide. This software is
// distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
@rmartinho
rmartinho / halcyon.md
Last active October 10, 2015 14:58
Halcyon

This document is an informal collection of design ideas for the Halcyon programming language. This document in in permanent draft status; do not take anything you read here as final. There are no plans to ever actually implement the ideas here; they're listed only for future reference.

Wants

  • Static, strong typing

    Type errors at runtime are stupid.

  • Type inference