Skip to content

Instantly share code, notes, and snippets.

View bl4ckb0ne's full-sized avatar

Simon Zeni bl4ckb0ne

  • Collabora
  • Canada
View GitHub Profile
@bl4ckb0ne
bl4ckb0ne / optional.cpp
Created November 11, 2019 16:08
optional_sfml_events
std::optional<const sf::Event> poll(sf::RenderWindow &rw)
{
if (f::Event e; rw.pollEvent(e))
{
return e;
}
return std::nullopt;
}
int main()
@bl4ckb0ne
bl4ckb0ne / ring_buffer.cpp
Last active August 1, 2019 19:22
Ring buffer
#include <assert.h>
#include <thread>
#include <atomic>
#include <vector>
#include <chrono>
#include <iostream>
#include <optional>
template <class T, size_t n>
#include <string>
#include <iostream>
#include <array>
class Foo
{
public:
Foo() : i(42), d(44.0) {}
template<typename T>
#include <iostream>
#include <array>
enum Log_level
{
L_SILENT = 0,
L_ERROR = 1,
L_INFO = 2,
L_DEBUG = 3,
};
@bl4ckb0ne
bl4ckb0ne / bintree.c
Created April 2, 2018 23:50
Binary tree in C
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
struct node
{
int data;
struct node* parent;
struct node* left;
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <memory>
#include <vector>
#if defined(VK_USE_PLATFORM_WIN32_KHR)
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
# Because build platform is different than target platform
set(CMAKE_CROSSCOMPILING TRUE)
set(TOOLCHAIN_USED "NI LinuxRT SDK 2017")
# Generator is force to Unix Makefiles to generate a makefiles
# Otherwise Visual Studio generator is there by default because
@bl4ckb0ne
bl4ckb0ne / TemplateMatrix.cpp
Last active July 10, 2017 18:16
Matrix with template parameters
#include <iostream>
#include <cassert>
template<typename T, int nrows, int ncols>
class StackMatrix
{
public:
StackMatrix()
{
static_assert(ncols != 0);
@bl4ckb0ne
bl4ckb0ne / smartptr_operator.cpp
Created March 26, 2017 20:26
Access an operator of an object inside a smart ptr http://coliru.stacked-crooked.com/a/f811a7e99cb58873
#include <iostream>
#include <vector>
#include <string>
#include <memory>
struct Foo
{
Foo(int size) : words(size, "Foo")
{}
#include <string>
#include <vector>
#include <tuple>
#include <iostream>
#include <experimental/tuple>
#define HI std::cout << __PRETTY_FUNCTION__ << '\n';
template <class Sig>
struct MsgQueue;