Skip to content

Instantly share code, notes, and snippets.

View nixiz's full-sized avatar
🎯
Focusing

Oguzhan KATLI nixiz

🎯
Focusing
View GitHub Profile
@nixiz
nixiz / two_singleton_dtor_problem.cpp
Last active August 14, 2018 15:49
What should happen during program shutdown if one Singleton's destructor tries to use another Singleton that's already been destroyed? The problem defined by Andrei Alexandrescu in book: Modern C++ Design: Generic Programming and Design Patterns Applied
#include <stdio.h>
/*
* Simple template singleton base class
*/
template<typename T>
class Singleton {
protected:
Singleton() = default;
Singleton(const Singleton&) = delete;
@nixiz
nixiz / const_placement_example.cpp
Last active February 27, 2019 13:20
const placement matters
template <typename T>
void test(T p) {
(*p)++; // increment by value
p++; // increment pointer to next element
}
void testrun1()
{
int value[2] {0, 1};
test<int *>(&value[0]); // 1. compiles and runs successfuly
#include <everything>
template <typename AnyThing>
[[ noreturn ]] void blackhole(AnyThing *obj)
{
delete obj;
}
@nixiz
nixiz / mersenne_twister_seed_finder.cpp
Last active June 18, 2019 07:42
mersenne twister algorithm seed finder for desired sequence of string.
// MersenneTwisterSeedFinder.cpp
// Copyright (c) Oguzhan KATLI. All rights reserved.
#include <random>
#include <string>
#include <iostream>
#include <thread>
#include <vector>
#include <numeric>
#include <algorithm>
@nixiz
nixiz / singleton.hpp
Last active September 17, 2021 07:11
#include <iostream>
#include <string>
#include <memory>
#include <cassert>
template <class T>
class Singleton
{
public:
using Type = typename std::remove_all_extents<T>::type;
#include <iostream>
namespace dtl // detail
{
template <typename T1, typename T2 = T1>
struct carpma_t {
typedef T1 tipi;
};
template <>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
#include <algorithm>
#include <execution>
using namespace std;
// fix mesaj tag'leri için kullanılacak parser sınıflarının deklerasyonları
@nixiz
nixiz / cache_friendly_programming.cpp
Last active December 2, 2022 08:15
cache friendly programming best practices with google/benchmark results
#include <benchmark/benchmark.h>
#include <iostream>
#include <random>
#include <algorithm>
#include <vector>
#include <chrono>
#include <iterator>
#include <execution>
static void count_if_random(benchmark::State& state)
@nixiz
nixiz / threadpool.cc
Last active October 12, 2023 20:30
thread pool implementation with modern c++. requires std=c++17 to build and run the tests. https://godbolt.org/z/6oTco3Tjz
#include <iostream>
#include <memory>
#include <thread>
#include <mutex>
#include <future>
#include <condition_variable>
#include <functional>
#include <vector>
#include <deque>
#include <type_traits>
@nixiz
nixiz / cpp20-range-example.cpp
Last active November 3, 2023 11:06
C++20 ranges example. Compiler Explorer link: https://godbolt.org/z/nG84M1j7a
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <chrono>
#include <random>
#include <range/v3/all.hpp>
#include <ranges>
using namespace std;