Skip to content

Instantly share code, notes, and snippets.

View Manu343726's full-sized avatar

Manu Sánchez Manu343726

View GitHub Profile
@Manu343726
Manu343726 / haskell_function.cpp
Created May 3, 2014 16:00
Haskell-like partial function calls for C++11
/****************************************************************************
* Haskell-like automatic partial functions *
* *
* Copyright © 2014 Manuel Sánchez Pérez *
* *
* This program is free software. It comes without any warranty, to *
* the extent permitted by applicable law. You can redistribute it *
* and/or modify it under the terms of the Do What The Fuck You Want *
* To Public License, Version 2, as published by Sam Hocevar. See *
* http://www.wtfpl.net/ for more details. *
@Manu343726
Manu343726 / main.cpp
Created November 21, 2014 14:48
tuple monad (with maybe for filtering)
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <experimental/optional>
#include <utility>
auto naked_tuple = [](auto... xs)
{
return [=](auto f)
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
@Manu343726
Manu343726 / gist:cd7b345e91d30271b1de
Last active August 29, 2015 14:23
Type-erased C++ ranges
//
// Created by manu343726 on 16/06/15.
//
#ifndef ERASED_RANGE_HPP
#define ERASED_RANGE_HPP
#include <range/v3/all.hpp>
#include <type_traits>
@Manu343726
Manu343726 / example.cpp
Last active August 29, 2015 14:26
piecewise_construct<T>(): Construct a T from tuple elements
#include "piecewise_construct.hpp"
struct foo
{
foo(int i, int j) :
i{i}, j{j}
{}
int i = 0, j = 0;
};
@Manu343726
Manu343726 / compiler_invocation.txt
Last active August 29, 2015 14:26
ctti example 1
g++ main.cpp -o ctti.s -S -O3 -Wno-unused-value -ftemplate-depth=2048 -DCTTI_MAX_STRING_LENGTH=128
@Manu343726
Manu343726 / compiler_invocation.txt
Created August 8, 2015 21:36
ctti example 1 (clang)
clang++ -std=c++14 main.cpp -o ctti.s -O3 -S -Wno-unused-value -ftemplate-depth=2048 -DCTTI_MAX_STRING_LENGTH=128
@Manu343726
Manu343726 / vs-unique-config.cmake
Created September 5, 2015 11:10
Workaround to make VS behave like unique-configuration generator
# Workaround to make VS behave like unique-configuration generator:
if(WIN32 AND MSVC)
set_target_properties([TARGET]
PROPERTIES EXCLUDE_FROM_ALL TRUE)
# Build [TARGET] using CMAKE_BUILD_TYPE always, as unique-configuration makefiles
add_custom_target(build_msvc ALL
COMMAND ${CMAKE_COMMAND} --build \".\" --target [TARGET] --config ${CMAKE_BUILD_TYPE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
@Manu343726
Manu343726 / vs_source_groups.cmake
Last active September 18, 2015 23:27
CMake script to generate Visual Studio source groups with the same structure as the project folder hierarchy
function(_generate_vs_source_groups GROUP_NAME TOP_DIRECTORY CURRENT_SUBDIRECTORY RESULT_FILES)
file(GLOB headers
${TOP_DIRECTORY}/${CURRENT_SUBDIRECTORY}/*.h
${TOP_DIRECTORY}/${CURRENT_SUBDIRECTORY}/*.hpp
${TOP_DIRECTORY}/${CURRENT_SUBDIRECTORY}/*.hh
${TOP_DIRECTORY}/${CURRENT_SUBDIRECTORY}/*.hxx
)
#include <vector>
#include <utility>
#include <algorithm>
void update(std::vector<bool>& map, std::size_t rows, std::size_t columns, bool(*rules)(std::size_t, bool))
{
auto at = [](std::size_t row, std::size_t column)
{
return row * columns + column;
};