Skip to content

Instantly share code, notes, and snippets.

View qrealka's full-sized avatar

Dmitry Loginov qrealka

View GitHub Profile
@qrealka
qrealka / AnyPointer.cpp
Created June 12, 2019 19:33
any pointer
#include <type_traits>
#include <any>
class AnyPointer {
public:
template <typename T,
typename = typename std::enable_if<std::is_pointer<typename std::remove_cv<T>::type>::value>::type>
AnyPointer(T ptr): any_(ptr) {}
template <typename ValueType>
@qrealka
qrealka / ccti.h
Last active June 9, 2019 23:02
operators POC
#pragma once
#include <string_view>
struct static_type_id {
static_type_id() = default;
constexpr static_type_id(const char* s, size_t len)
: name{s}, size{len}, hash{fnv1a_hash(len, s)}
{}
friend constexpr bool operator==(const static_type_id& lhs, const static_type_id& rhs) noexcept
@qrealka
qrealka / hash_fnv1a.h
Created June 7, 2019 20:57 — forked from ruby0x1/hash_fnv1a.h
FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
#pragma once
#include <stdint.h>
//fnv1a 32 and 64 bit hash functions
// key is the data to hash, len is the size of the data (or how much of it to hash against)
// code license: public domain or equivalent
// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
inline const uint32_t hash_32_fnv1a(const void* key, const uint32_t len) {
@qrealka
qrealka / init_array.cpp
Created June 7, 2019 16:33
draft version of init array in compile time cpp14
#include <array>
#include <utility>
enum class SomeEnum : int {
item1 = 0,
item2,
item3,
size
};
@qrealka
qrealka / generate.md
Created June 5, 2019 16:21
Generate call graph by clang
static void D() { }
static void Y() { D(); }
static void X() { Y(); }
static void C() { D(); X(); }
static void B() { C(); }
static void S() { D(); }
static void P() { S(); }
static void O() { P(); }
static void N() { O(); }
cmake_minimum_required(VERSION 2.8)
set(CMAKE_INSTALL_PREFIX /usr)
project(UNITY_BUILD_NAME)
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
@qrealka
qrealka / is-complete.h
Created May 31, 2019 10:28
c++ is_complete traits
#include <type_traits>
struct S;
template<typename T>
class test_complete_type {
T obj;
};
template<typename T, typename = void>
#include <cstring> // memcpy
#include <type_traits> // is_trivially_copyable
// http://src.chromium.org/viewvc/chrome/trunk/src/base/basictypes.h?view=markup
// bit_cast<Dest,Source> is a template function that implements the
// equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in
// very low-level functions like the protobuf library and fast math
// support.
//
@qrealka
qrealka / how-to-install-latest-gcc-on-ubuntu-lts.txt
Created March 17, 2019 04:48 — forked from application2000/how-to-install-latest-gcc-on-ubuntu-lts.txt
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04)
These commands are based on a askubuntu answer http://askubuntu.com/a/581497
To install gcc-6 (gcc-6.1.1), I had to do more stuff as shown below.
USE THOSE COMMANDS AT YOUR OWN RISK. I SHALL NOT BE RESPONSIBLE FOR ANYTHING.
ABSOLUTELY NO WARRANTY.
If you are still reading let's carry on with the code.
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
@qrealka
qrealka / bitmasks.cpp
Created February 27, 2019 13:19
c++ compile-time bitmasks
// https://stackoverflow.com/questions/54786278/how-do-i-write-a-maintainable-fast-compile-time-bit-mask-in-c
#include <bitset>
enum Flags { A = 1, B = 2, C = 3, D = 5,
E = 8, F = 13, G = 21, H,
I, J, K, L, M, N, O };
#define CPP_VERSION 14
#if CPP_VERSION==11