Skip to content

Instantly share code, notes, and snippets.

@dtoma
dtoma / tt.cpp
Created April 7, 2017 03:40
tuples types
#include <tuple>
// Macro to declare elements of an `enum class`
#define DEFINE_ENUM_TYPE(type, id) type = id,
// Declare currencies
#define CURRENCIES(code) \
code(USD, 0) \
code(EUR, 1)
@dtoma
dtoma / ini.cpp
Created March 24, 2017 08:43
ini configuration reader
#include <algorithm>
#include <optional>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <cstdio>
// http://tristanbrindle.com/posts/a-quicker-study-on-tokenising/
template <typename Iterator, typename Lambda>
@dtoma
dtoma / ringbuffer.cpp
Created February 24, 2017 08:17
ringbuffer
#include <array>
#include <iostream>
#include <iomanip>
namespace {
template <typename T, std::size_t N>
auto print_array(std::array<T, N> a) {
std::cout << "array: |";
for (auto const& e : a) {
std::cout << std::setw(2) << e << "|";
@dtoma
dtoma / gcc_perf_attributes.md
Last active February 22, 2017 06:58
gcc attributes for perf tuning

error/warning

Code exammple:

#include <string>

std::string __attribute__((warning("getString not inlined/removed"))) getString() {
  return "Foo";
}
@dtoma
dtoma / pi.cpp
Created February 21, 2017 03:05
C++ OpenMP Pi
// http://jakascorner.com/blog/2016/05/omp-monte-carlo-pi.html
#include <iostream>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <iomanip>
#include <limits>
#include <chrono>
@dtoma
dtoma / bcc1.cpp
Created February 20, 2017 09:15
book: beautiful code, chapter 1
/*
* Character | Meaning
* c | Matches any literal character c
* . | Matches any single character
* ^ | Matches the beginning of the input string
* $ | Matches the end of the input string
* * | Matches zero or more occurrences of the previous character
*/
#include <cstdio>
@dtoma
dtoma / asiaconf.md
Last active January 30, 2017 08:54
Conferences in Asia 2017
@dtoma
dtoma / fix.cpp
Last active January 3, 2017 08:02
ideas for fix parsing/serializing
// http://ldionne.com/hana-cppnow-2015/
// http://boostorg.github.io/hana/
// note: re-read the CppCon pres on fusion for parsing
// somehow hold the tag and value type in the field's type?
template <int Tag, typename T>
struct Field { T value; }
template <int Tag, typename T>
constexpr auto get_tag(field<Tag, T>&&) { return Tag; }
@dtoma
dtoma / Makefile
Last active November 5, 2022 14:46
makefile rules to check style using clang-format
style:
@for src in $(SOURCES) ; do \
echo "Formatting $$src..." ; \
clang-format -i "$(SRC_DIR)/$$src" ; \
clang-tidy -checks='-*,readability-identifier-naming' \
-config="{CheckOptions: [ \
{ key: readability-identifier-naming.NamespaceCase, value: lower_case },\
{ key: readability-identifier-naming.ClassCase, value: CamelCase },\
{ key: readability-identifier-naming.StructCase, value: CamelCase },\
{ key: readability-identifier-naming.FunctionCase, value: camelBack },\