Skip to content

Instantly share code, notes, and snippets.

View DrkWithT's full-sized avatar
🎯
Focusing

Tan, Derek DrkWithT

🎯
Focusing
  • California, USA
View GitHub Profile
#include <array>
#include <type_traits>
#include <print>
/// Compiled on g++ with: -std=c++23 -Og
/// Util. types
enum class StepPolicy {
forth,
#include <type_traits>
#include <iostream>
struct Foo {};
template <typename... Args>
struct TypeList {};
template <int N, typename Target>
constexpr int searchTypeImpl() {
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef enum {
thing_flag,
thing_number,
thing_nil
} Thing;
#include <utility>
#include <concepts>
#include <algorithm>
#include <array>
#include <string>
template <template <typename> typename Buffer, typename ItemT>
concept BufferKind = requires(Buffer<ItemT>&& arg, std::size_t count) {
{arg.getPtr()} -> std::same_as<ItemT*>;
{arg.getSize()} -> std::same_as<std::size_t>;
@DrkWithT
DrkWithT / CompileTimeCalc.cpp
Created January 31, 2025 18:42
A compile time postfix expression evaluator demo.
#include <algorithm>
#include <array>
#include <string_view>
#include <utility>
#include <print>
// This was compiled and ran on Compiler Explorer:
// Compiler flags: -std=c++26 -Og
// Note: The call operator for the evaluator did not get generated at all, and the expected result of 42 was embedded in a single MOV.
@DrkWithT
DrkWithT / Sample_Func.cpp
Created January 31, 2025 18:36
Example function wrapper for educational purposes
#include <memory>
#include <iostream>
enum class MyStorageKind {
static_ptr, // pointer to non-member function
dud_ptr
};
template <typename Result, typename... Args>
class MyFunc {
@DrkWithT
DrkWithT / MyTemplatePair.cpp
Created July 9, 2024 03:47
My toy implementation of C++ STL pair class.
#include <type_traits>
#include <utility>
#include <stdexcept>
#include <print>
template <std::size_t Index, typename T1, typename T2>
struct TpChooser {};
template <typename T1, typename T2>
struct TpChooser<0, T1, T2>
@DrkWithT
DrkWithT / ToyOptional.cpp
Last active July 7, 2024 18:11
A toy C++ optional implementation for educational purposes. Follows some cppreference points.
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <iostream>
// Optional v2: semi-serious attempt using cppref as a reference.
// NOTE: There are some caveats e.g not handling pointer types, etc.
namespace toy {
@DrkWithT
DrkWithT / MyAny.hpp
Created June 13, 2024 05:59
A toy C++ Any implementation for educational purposes.
#ifndef MY_ANY_HPP
#define MY_ANY_HPP
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <memory>
#include <typeinfo>
/*
#include <iostream>
/*
Attempt at CRTP visitor sample
DrkWithT
*/
/// Forward decls. of visitable objects
class OneBox;
class TwoBox;