Skip to content

Instantly share code, notes, and snippets.

View gomons's full-sized avatar

Sergey Gomon gomons

  • Warsaw, Poland
  • 05:56 (UTC +01:00)
View GitHub Profile
@gomons
gomons / zlib_strings.cpp
Last active March 6, 2023 17:57
Compressing STL Strings with zlib
// Copyright 2007 Timo Bingmann <tb@panthema.net>
// Distributed under the Boost Software License, Version 1.0.
// (See http://www.boost.org/LICENSE_1_0.txt)
//
// Original link http://panthema.net/2007/0328-ZLibString.html
#include <string>
#include <stdexcept>
#include <iostream>
#include <iomanip>
@gomons
gomons / to_underlying.cpp
Last active June 15, 2016 08:02
Convert enum class value to undrlying type
template <typename E> constexpr typename std::underlying_type<E>::type to_underlying(E e) {
return static_cast<typename std::underlying_type<E>::type>(e);
}
@gomons
gomons / endianness.cpp
Last active April 3, 2016 20:56
Convert endianness of integral types.
// Original: http://stackoverflow.com/a/12867287/1091536
// Usage:
// To convert from given endian to host, use:
// host = endian(source, endian_of_source)
// To convert from host endian to given endian, use:
// output = endian(hostsource, endian_you_want_to_output)
enum class Endian: int {
Big = 1, Little = 0
};