Skip to content

Instantly share code, notes, and snippets.

@ghtz08
ghtz08 / format.hpp
Created June 20, 2022 08:31
简易的 format
namespace details {
template <size_t fmt_len, typename... Args>
struct format_to_h;
template <size_t fmt_len, typename Arg, typename... Args>
struct format_to_h<fmt_len, Arg, Args...> {
auto operator()(std::ostream & out, char const (&fmt)[fmt_len], size_t fmt_start, Arg && arg, Args && ... args) -> void {
auto const braces = std::strstr(&fmt[fmt_start], "{}");
if (braces == nullptr) {
format_to_h<fmt_len>()(out, fmt, fmt_start);
@ghtz08
ghtz08 / ipv4.cpp
Created August 15, 2021 09:25
IPv4 的封装
#define let auto const
class Ipv4 {
public:
using Value = std::array<uint8_t, 4>;
static constexpr auto ipv4_str_max_size = 3 + 1 + 3 + 1 + 3 + 1 + 3 + 1;
public:
explicit Ipv4(char const * ipv4, bool strict = false):
Ipv4(ipv4, -1, strict) {}
@ghtz08
ghtz08 / registry.hpp
Last active August 2, 2022 03:38
注册器,可自定义 Key
#include <memory>
#include <stdexcept>
#include <string>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#define let auto const
// 约束