Skip to content

Instantly share code, notes, and snippets.

@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 {};
@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;