Skip to content

Instantly share code, notes, and snippets.

@flisboac
flisboac / c-api-visibility
Last active August 9, 2016 01:43
C API Visibility
An example and framework on C/C++ API design and symbol visibility.
@flisboac
flisboac / test-interface-method-dispatch.cpp
Last active September 21, 2016 10:22
Testing different dynamic method dispatch techniques in C++11. Compile with `--std=c++11` or equivalent.
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <memory>
#include <functional>
#include <chrono>
#include <type_traits>
#include <thread>
#include <algorithm>
@flisboac
flisboac / test-better-cpp-enums
Last active September 21, 2016 10:21
Testing new enum schemes in C++
Testing new enum schemes in C++
@flisboac
flisboac / reverse-flist-inplace.c
Last active September 23, 2016 07:45
A silly (and rather naive) implementation for a test question I stumbled upon these days. The subject was (obviously) Data Structures.
/*----------------------------------------------------------------------------------------------------
* flist.h : Library header
*/
#ifndef FLIST_H_
#define FLIST_H_
@flisboac
flisboac / libtemplate.h
Created September 25, 2016 06:31
A simple library template for multi-link mode (static/shared) library headers.
#if 0
To use, copy/paste and substitute LIBNAME with your library's name.
Names:
- Exported -> void function();
- Imported -> extern void function();
- Internal -> static function();
[ API] Exported names, when compiling:
@flisboac
flisboac / timer.hpp
Last active September 27, 2016 11:12
A pretty simple timer class (header-only) in C++11 that also calculates the average/minimum/maximum time of multiple measurements.
#ifndef TIMER_HPP_
#define TIMER_HPP_
#include <iosfwd>
#include <type_traits>
#include <chrono>
class Timer {
public:
using Clock = std::conditional<
@flisboac
flisboac / test-method-dispatch-benchmark.cpp
Last active September 27, 2016 15:56
A quick and dirty method dispatch benchmark intended to measure method execution time in some scenarios (e.g. inheritance vs method pointers, things like that). Portable C++11, no compiler extensions.
#include <iostream>
#include <chrono>
#include <thread>
#include <type_traits>
#include <vector>
#include <random>
#include <iomanip>
#include <array>
#include <algorithm>
#include <sstream>
@flisboac
flisboac / circular_list.hpp
Created September 27, 2016 07:52
A header-only circular doubly-linked list implementation in C++11. Don't know exactly how I came to need and implement it in the first place, but here it is, nonetheless.
#ifndef CIRCULAR_LIST_
#define CIRCULAR_LIST_
template <typename T>
class circular_list {
private: // static members
struct node {
public: // methods
node() = default;
@flisboac
flisboac / Limite.java
Created November 5, 2016 13:36
Pequena classe de limites contínuos. Guardando para uso posterior, ou não.
package seguradora.fuzzy.util;
import java.math.BigDecimal;
public class Limite {
private Number inferior;
private Number superior;
public Limite() {
@flisboac
flisboac / test-fila-circular-stack.c
Created December 13, 2016 02:02
Implementação de uma fila circular sem alocação dinâmica interna em C, através de índices em uma array de tamanho fixo.
#include <stdio.h>
#include <stdlib.h>
#define CAPACIDADE 5
#define SIMNAO(_b_) ((_b_) ? "sim" : "não")
#define VALOR_PADRAO (0)
// Algumas notas acerca do uso dos índices primeiro e último:
// - f->primeiro é sempre um indice válido que vai de 0 a (CAPACIDADE - 1),
// apontando para o primeiro elemento da fila