Skip to content

Instantly share code, notes, and snippets.

View ecatmur's full-sized avatar
👻

Ed Catmur ecatmur

👻
  • Maven Securities
  • Chicago
View GitHub Profile
#include <boost/asio.hpp>
#include <boost/asio/experimental/promise.hpp>
#include <boost/beast/core/tcp_stream.hpp>
#include <boost/beast/websocket/stream.hpp>
boost::asio::awaitable<void> echo(boost::beast::websocket::stream<boost::beast::tcp_stream>& stream) {
for (;;) {
boost::beast::flat_buffer buf;
co_await stream.async_read(buf, boost::asio::use_awaitable);
co_await stream.async_write(buf.data(), boost::asio::use_awaitable);
@ecatmur
ecatmur / README.md
Last active July 6, 2022 20:30
piecewise-construct-ub
$ g++ --version
g++ (GCC) 12.1.0
$ g++ -O2 -std=c++14 a.cpp main.cpp && ./a.out
a.out: main.cpp:5: int main(): Assertion `f() == (*c().target<F*>())()' failed.
Aborted
$ clang++ --version
clang version 14.0.5
@ecatmur
ecatmur / 00-godbolt.md
Last active July 4, 2022 22:38
Advanced metaprogramming for low-latency trading, Maven-style
#include <boost/assert/source_location.hpp>
#include <algorithm>
#include <source_location>
#if not _MSC_VER
template<unsigned M, unsigned N>
#endif
struct sloc_literal {
#if _MSC_VER
char const* file = nullptr;
#include <type_traits>
template<class, auto, auto, auto>
class accessor;
template<class C, auto id, auto getter, auto setter>
class property : public decltype(
id.template operator()<accessor<C, id, getter, setter>>())::type {};
template<class C, auto id, auto getter, auto setter>
@ecatmur
ecatmur / README.md
Last active March 14, 2022 15:00
functional cast as direct initialization
@ecatmur
ecatmur / references.md
Last active June 16, 2022 15:04
Motivating examples for relocation
#!/bin/bash
NOBLOB=0000000000000000000000000000000000000000
root=$(git rev-parse --show-toplevel) || exit
revs=()
for arg; do
if [[ $arg == *...* ]] ; then
revs+=($(git name-rev --name-only --always ${arg%...*})
@ecatmur
ecatmur / constexpr-allocation.cpp
Last active May 7, 2021 14:42
Constexpr string processing and dropping to runtime via std::array
#include <array>
#include <iostream>
#include <string>
#include <utility>
#if __cpp_lib_constexpr_string >= 201907L
using string = std::string;
#else
struct string {
using value_type = char;
@ecatmur
ecatmur / relocate.cpp
Last active February 11, 2021 17:38
Library relocate
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4158.pdf
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0023r0.pdf
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1029r3.pdf
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1144r5.html
#include <type_traits>
#include <utility>
struct relocates{};
template<class T> constexpr bool is_relocatable_v = std::is_constructible_v<T, relocates, T*>;