Skip to content

Instantly share code, notes, and snippets.


R. Martinho Fernandes rmartinho

View GitHub Profile
rmartinho / gist:9485770
Last active Apr 9, 2019
Program that swaps the values of variables x and y, with the usual algorithm that uses a temporary variable in a weird nonexistent language.
View gist:9485770
temporary_ACC creation_V.
temporary_DAT assignment_V x_ACC.
y_ACC x_DAT assignment_V.
assignment_V temporary_ACC y_DAT.
View gist:8838284
BOOST_DEFINE_MATH_CONSTANT(half, 5.000000000000000000000000000000000000e-01, "5.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-01")
rmartinho / bit_ops.cpp
Created Apr 24, 2013 — forked from bananu7/bit_ops.cpp
Bit twiddling tools. I got tired of primitive stuff like & and |
View bit_ops.cpp
template <int Size>
struct uint_least : uint_least<Size+1> {};
template <>
struct uint_least<8> : identity<u8> {};
template <>
struct uint_least<16> : identity<u16> {};
template <>
struct uint_least<32> : identity<u32> {};
template <>
struct uint_least<64> : identity<u64> {};
rmartinho / stack_alloc.h++
Created Apr 17, 2013
Just a sample of what kind of magic I think could make a C++ alloca().
View stack_alloc.h++
// 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 / fast.c++
Last active Dec 16, 2015
“I want it as fast as possible”
View fast.c++
int main(){}
View regex_text
$ locale
rmartinho / future.c++
Created Mar 24, 2013
Sample implementation of std::future
View future.c++
#include <wheels/concurrency/locker_box.h++>
#include <chrono>
#include <exception>
#include <future>
#include <memory>
#include <mutex>
#include <type_traits>
#include <utility>
rmartinho / flavoured_strings.cpp
Created Mar 23, 2013
Using char_traits to get strong string aliases.
View flavoured_strings.cpp
#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 / 01broken_vector.cpp
Last active Dec 15, 2015
Never pass vectors by reference. Wait, never pass ints by reference. Better, never pass anything by reference.
View 01broken_vector.cpp
struct Gadget
std::vector<Widget> w;
void thread1()
Gadget g;
rmartinho / expand.h++
Last active Dec 14, 2015
Some lousy simple logger
View expand.h++
// Internal Combustion Engine
// 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 <>.