Skip to content

Instantly share code, notes, and snippets.

@eao197
eao197 / protected_ptr_demo.cpp
Created July 21, 2020 05:36
Развитие идеи protected_ptr, предложенной Николаем Меркиным в обсуждении в FB.
#include <memory>
#include <iostream>
#include <string>
using namespace std;
template< typename T >
class protected_ptr
{
shared_ptr<T> m_object;
@eao197
eao197 / gist:8e5524eb8b0e6688e310d34492d9267a
Created March 2, 2023 04:37
Примеры сообщений об ошибках для разных реализаций tagged_value_t
Источник: https://eao197.blogspot.com/2023/03/progc-taggedvaluet.html
Компилятор clang 14.0.6.
Объемная версия на базе SFINAE:
-----
$ clang++-14 -std=c++17 -pedantic -Wall -o t1_clang14 t1.cpp
t1.cpp:198:24: error: overload resolution selected deleted operator '<'
const auto cr = (bin1 < bin2);
@eao197
eao197 / mutil_sink_impl_benchmark.cpp
Created March 21, 2023 05:03
Бенчмарк для проверки производительности двух разных вариантов реализации multi_sink_bindings в SO-5.8
#include <iostream>
#include <chrono>
#include <vector>
#include <so_5/all.hpp>
using hires_clock = std::chrono::high_resolution_clock;
struct msg_01 final : public so_5::signal_t {};
struct msg_02 final : public so_5::signal_t {};
@eao197
eao197 / shared_ptr_for_const_object.cpp
Created April 13, 2023 04:49
Пример, который на wandbox сломал компилятор clang-16.0.1 (на строчке с инициализацией initial внутри make)
#include <cstddef>
#include <iostream>
#include <memory>
#include <vector>
struct MyData {
std::vector<std::byte> m_data;
explicit MyData(std::vector<std::byte> data) : m_data{std::move(data)}
{}
@eao197
eao197 / locals.mxx
Created October 6, 2023 07:10
Пример проектных файлов для m++ v3 (эти файлы использовались для компиляции m++v4 посредством m++v3)
if defined( "UNIX" ) && !defined( "GNU" )
define "GNU";
objPath = "o";
if !defined( "NOAUTODEP" ) {
autodepIncludePathList += ".";
autodepIncludePathList += "h";
autodepIncludePathList += "mxx/h";
}
@eao197
eao197 / restinio_server_addr_parser.cpp
Created November 28, 2023 10:52
Пример парсинга адреса сервера вида "http://localhost:8088/" имеющимися в RESTinio средствами. С разбором на составляющие: (http|https), (host|ipv6|ipv4) и опциональный порт
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <restinio/helpers/http_field_parsers/host.hpp>
namespace example
{
namespace ep = restinio::easy_parser;
@eao197
eao197 / adv_thread_pool_cooperative.cpp
Created January 11, 2024 05:24
An example of adv_thread_pool with cooperative FIFO
#include <so_5/all.hpp>
struct m1 final : public so_5::signal_t {};
struct m2 final : public so_5::signal_t {};
struct m3 final : public so_5::signal_t {};
struct done final : public so_5::signal_t {};
class A final : public so_5::agent_t
{
public:
@eao197
eao197 / isdefault_impl_benchmark.cpp
Created January 19, 2024 07:20
Примитивный бенчмарк для демонстрации скорости работы разных реализаций isDefault
#include <chrono>
#include <iostream>
#include <string>
#include <variant>
namespace isdefault_benchmark
{
class time_meter_t
{
@eao197
eao197 / sketch.cpp
Created February 9, 2024 09:58
Вольная вариация на тему std::latch, но для ситуации, когда значение счетчика заранее неизвестно.
class meeting_room_t {
std::mutex lock_;
std::condition_variable wakeup_cv_;
unsigned attenders_{};
public:
meeting_room_t() = default;
void enter() {
@eao197
eao197 / same_stop_guard_several_times.cpp
Created March 2, 2024 07:15
A demo of using the same stop_guard several times
#include <so_5/all.hpp>
#include <iostream>
class shutdown_initiated final : public so_5::signal_t {};
class my_stop_guard final : public so_5::stop_guard_t
{
const so_5::mbox_t m_dest;