Skip to content

Instantly share code, notes, and snippets.

@saltzm
saltzm / comptime_list.zig
Last active August 22, 2022 00:12
Compile Time List in Zig
const std = @import("std");
fn List(comptime Head: type, comptime Tail: type) type {
return struct {
const Self = @This();
head: Head,
tail: Tail,
fn prepend(comptime self: Self, comptime item: anytype) List(@TypeOf(item), Self) {
return List(@TypeOf(item), Self) { .head = item, .tail = self };
@saltzm
saltzm / baton.zig
Created August 6, 2022 19:26
Async Baton in Zig
const Baton = struct {
waiters: RingBuffer(anyframe, 1024) = .{},
const Self = @This();
pub fn yield(self: *Self) !void {
suspend {
try self.waiters.enqueue(@frame());
}
}
#include <iostream>
#include <type_traits>
template <typename Head, typename Tail = std::nullptr_t>
class List {
public:
List(Head h) : _head(std::move(h)) {}
List(Head h, Tail t) : _head(std::move(h)), _tail(std::move(t)) {}
template <typename T>
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
inline constexpr bool isVariant = false;
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
inline constexpr bool isVariant = false;
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
inline constexpr bool isVariant = false;
#include <memory>
#include <iostream>
#include <variant>
#include <optional>
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template <typename... Ts>
inline constexpr bool isVariant = false;