Skip to content

Instantly share code, notes, and snippets.

View shoooe's full-sized avatar
🏓

Thomas Pigarelli shoooe

🏓
View GitHub Profile
@shoooe
shoooe / any.hpp
Last active July 5, 2021 02:19
A simple implementation of Boost's any, as an exercise.
#pragma once
#include <exception>
#include <memory>
#include <typeinfo>
#include <type_traits>
class any;
template<class Type> Type any_cast(any&);
@shoooe
shoooe / filetoobig.md
Last active May 9, 2021 12:34
The asymmetries of C++

The asymmetries of C++

This is lighthearted collection of asymmetries of the C++ language. This is not, in any way, intended as a critic.


Partial specialization is allowed for class templates but not for function templates

§14.5.5 [temp.class.spec] describes the semantic and syntax for class template partial specialization such as, given:

Why is the codomain useful?

In set theory we have that a domain is the set of all inputs for which a function is defined and the image is the set of possible outputs given those inputs. You would think this would be enough, but no: we also have the concept of codomain, which is the set of all possible outputs and some.

This also leads to the distinction between "surjective" functions and non-"surjective" functions (functions that have the image being equal to the codomain and those that don't, respectively). This distinction seems to provide no useful information about the function itself.

Now, let's make an example, we have:

ƒ : {a, b, c, d} -> {1, 2, 3, 4}

ƒ a = 1

Keybase proof

I hereby claim:

  • I am shoooe on github.
  • I am tpigarelli (https://keybase.io/tpigarelli) on keybase.
  • I have a public key ASCbdD34wOQtajdGmowxTw6Vce6Ce5CKBsPf926SpZ0tMwo

To claim this, I am signing this object:

#include <iostream>
#include <memory>
#include <cassert>
enum class node_color {
red,
black
};
template<typename DataType>
#include <numeric>
namespace std {
template<class T, std::size_t N, std::size_t M>
T* begin(T (&array)[N][M]) {
return &array[0][0];
}
template<class T, std::size_t N, std::size_t M>
@shoooe
shoooe / bitboard.hpp
Last active December 29, 2015 06:49
Bitboard boilerplate code.
template<std::size_t Cols, std::size_t Rows>
class bitboard {
private:
std::bitset<Cols * Rows> _bitset;
public:
using reference = std::bitboard<Cols, Rows><Cols * Rows>::reference;
reference operator()(std::size_t, std::size_t);
bitboard<Cols, Rows>& operator&=(const bitboard<Cols, Rows>&);
bitboard<Cols, Rows>& operator|=(const bitboard<Cols, Rows>&);
namespace detail {
template<typename It>
It partition(It begin, It end) {
if (begin == end) return end;
auto pivot = *(end - 1);
auto left = begin; // left partion past the end
for (auto right = begin; right != end; ++right) {
if (*right <= pivot) {
std::iter_swap(left, right);
@shoooe
shoooe / equal100.hs
Last active August 29, 2015 14:20
Solution to the fifth problem found here: https://goo.gl/eEyf9x, because it took longer than it should have.
-- Write a program that outputs all possibilities to put + or - or nothing
-- between the numbers 1, 2, ..., 9 (in this order) such that the result is
-- always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
import Control.Monad (replicateM)
ints :: [String]
ints = map (\i -> [i]) ['1'..'9']
inbetweens :: [[String]]
type alias Unit = Float
type Vec2 = Vec2 Unit Unit
(|+|) : Vec2 -> Vec2 -> Vec2
(Vec2 ax ay) |+| (Vec2 bx by) = Vec2 (ax + bx) (ay + by)
negate : Vec2 -> Vec2
negate (Vec2 x y) = Vec2 (-x) (-y)
(|-|) : Vec2 -> Vec2 -> Vec2