Skip to content

Instantly share code, notes, and snippets.

@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 / 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;
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
using namespace std::chrono;
struct lock_context
{
@eao197
eao197 / restinio_handle_post_body_x_www_form_urlencoded.cpp
Created April 10, 2020 08:49
An example of handling POST body with x-www-form-urlencoded content type in RESTinio 0.6.5
#include <restinio/all.hpp>
#include <restinio/helpers/http_field_parsers/content-type.hpp>
#include <fmt/format.h>
using router_t = restinio::router::express_router_t<>;
auto handle_post_body(
const restinio::request_handle_t & req )
@eao197
eao197 / restinio_github_issue_22_2.cpp
Created May 11, 2019 12:59
An example of chunk_encoding response with RESTinio and SO-5.5
#include <restinio/all.hpp>
#include <so_5/all.hpp>
#include <random>
// Message for transfer requests from RESTinio's thread to processing thread.
struct handle_request
{
restinio::request_handle_t m_req;
@eao197
eao197 / message_holder-simplified.cpp
Created April 23, 2019 06:13
Полный код для статьи о деталях реализации message_holder_t из SObjectizer-5.6
template< typename Payload, typename Envelope >
class basic_message_holder_impl_t
{
protected :
intrusive_ptr_t< Envelope > m_msg;
public :
using payload_type = Payload;
using envelope_type = Envelope;
@eao197
eao197 / so5extra-asio_thread_pool.hpp
Created April 17, 2019 12:21
The source code of so5extra's implementation of Asio's based thread_pool dispatcher for SObjectizer-5.6
/*!
* \file
* \brief Implementation of Asio's Thread Pool dispatcher.
*
* \since
* v.1.0.2
*/
#pragma once
@eao197
eao197 / adv_example.cpp
Created April 12, 2019 06:07
CTRP and C++ template magic for compile-time control (more advanced version)
#include <iostream>
enum class msg_count_status_t
{
undefined,
defined
};
struct basic_data_t
{
@eao197
eao197 / example.cpp
Created April 11, 2019 17:30
CTRP and C++ template magic for compile-time control
#include <iostream>
enum class msg_count_status_t
{
undefined,
defined
};
struct basic_data_t
{
@eao197
eao197 / dining_philosophers_dijkstra_csp_based.cpp
Created January 25, 2019 07:12
Simple implementation of Dijkstra solution for Dining Philosophers problem. This implementation is built on top of std::threads and CSP-like channels from SObjectizer-5.5
#include <dining_philosophers/common/fork_messages.hpp>
#include <dining_philosophers/common/random_generator.hpp>
#include <dining_philosophers/csp_based/trace_maker/all.hpp>
#include <fmt/format.h>
#include <queue>
void fork_process(