Skip to content

Instantly share code, notes, and snippets.

View ikskuh's full-sized avatar
☺️
Hacking on Dunstwolke

Felix Queißner ikskuh

☺️
Hacking on Dunstwolke
View GitHub Profile
@ikskuh
ikskuh / tagged_int.hpp
Created April 26, 2019 14:13
Tagged, configurable integer type which allows only "self-interaction"
#include <type_traits>
template<
typename Tag, // Discriminator
typename UnderlyingType = std::size_t, // What integer are we defining
bool EnableOrdering = true, // Allow relational operators
bool EnableBitwise = false, // Allow bitwise operators
bool EnableArithmetic = false // Allow arithmetic operators
>
struct tagged_int
@ikskuh
ikskuh / modern-c++.md
Last active December 8, 2018 14:26
C++ Cheat Sheet & Brain Markers
  • std::byte for "plain byte data" instead of char, unsigned char or uint8_t
  • use std::optional<T> for optional return values (kinda obvious, but you have to know)
  • std::variant<T1,T2,...> is a C++ version of union
  • use std::bitset<N> for bitfields
  • structured bindings are useful for multiple return values:
    std::tuple<std::string, int>> get_name_and_age();
    auto [ name, age ] = get_name_and_age();
@ikskuh
ikskuh / soundwaves-ogg.cpp
Last active December 8, 2020 13:15
Getting started with SDL2 sound generation: Simple sine wave synth with moving the freq up and down
#include <SDL.h>
#include "stb_vorbis.h"
short audiodata[4096];
volatile bool needsData = true; // poor mans semaphore
void callback(void* userdata, Uint8* stream, int len)
{
printf("%p,%d\n", stream, len);
while(needsData); // yay