Skip to content

Instantly share code, notes, and snippets.

@eao197
eao197 / templates_part1.cpp
Last active April 10, 2024 07:55
Примеры для первой части лекции про шаблоны C++
/***
Реализация шаблона должна быть доступна компилятору.
Поэтому шаблоны размещают в .hpp-файлах
*/
/////////////////////////////////////////////////////
/***
@eao197
eao197 / custom_data_source_message.cpp
Created March 12, 2024 12:17
An example of sending so_5::stats::messages::quantity<int> via custom data-source
#include <so_5/all.hpp>
namespace example
{
class a_stats_listener_t final : public so_5::agent_t
{
public :
a_stats_listener_t( context_t ctx )
: so_5::agent_t( std::move(ctx) )
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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 {};