Skip to content

Instantly share code, notes, and snippets.

View day02's full-sized avatar

day day02

View GitHub Profile
#include <iostream>
#include <vector>
#include <stdexcept>
#include <format>
template <typename Type>
struct Mat_2D{
using index_t = unsigned long;
Mat_2D(const index_t row,
#include <iostream>
#include <cassert>
template <typename T>
struct counter {
counter() { update_counter(); }
counter(counter&) { update_counter(); }
counter(counter&&) = default;
counter& operator=(counter&) { update_counter(); }
counter& operator=(counter&&) = default;
// Covarience to copy derived classes with raw pointers.
#include <iostream>
#include <cassert>
class Base {
public:
explicit Base(const int value) : m_value(value) {}
// can not have copy constructor or assignment
// with polymorphic classes.
Base(Base&) = delete;
#include <vector>
#include <memory>
#include <mutex>
#include <thread>
#include <cassert>
template<typename Type>
struct monitor {
template<typename ...Args>
monitor(Args&&... args) :
#include <iostream>
struct base {
base (int a) { std::cout << "base constructor : " << a << std::endl; }
virtual ~base() = default;
};
struct derived : base {
// inheriting constructors
using base::base;
// pass key idom.
#include <iostream>
#include <unordered_map>
struct citizen {
private:
struct access_to_social_security;
public:
explicit citizen(const std::string name,
#include <iostream>
#include <cassert>
// finite state machine where we statically checked.
// A -> [D],
// B -> [D, E]
// C -> [E]
struct [[nodiscard]] consume_t {
consume_t() = default;
#include <iostream>
#include <thread>
struct [[nodiscard]] binary_spin_lock_t
{
explicit binary_spin_lock_t(int pid_);
void lock(const binary_spin_lock_t &other);
void unlock();
private:
int pid{0};
#include <iostream>
#include <vector>
#include <cassert>
namespace lib {
template<typename iterator_t, typename data_t = iterator_t::type_trait::value>
iterator_t binary_search(iterator_t begin, iterator_t end, const data_t &data);
}
template<typename iterator_t, typename data_t = iterator_t::type_trait::value>
#include <iostream>
#include <string_view>
#include <fmt/core.h>
#include <experimental/source_location>
#include <stdexcept>
#include <memory>
template <typename ...Args>
struct LOG
{