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
/*
SmartAdder.cpp
Brief: When concepts make template candidate resolution easier! This is a toy example.
Working Link: https://godbolt.org/z/sWWehffdT
Date: 05/28/2024
*/
#include <exception>
#include <iostream>
/*
MyFirstTuple.cpp
Date: 05/28/2024
*/
#include <exception>
#include <iostream>
/// utility struct extracting a type name from a variadic list of type names
@DrkWithT
DrkWithT / ConcatVectors.cpp
Last active May 5, 2024 17:45
A naively implemented vector concatenating function. Works in C++17 and beyond.
#include <algorithm>
#include <vector>
#include <iostream>
// item counting helper, base case
template <template<typename> typename V, typename T, typename... Args>
[[nodiscard]] constexpr size_t deduceItemTotal(const V<T>& arg) {
return arg.size();
}
@DrkWithT
DrkWithT / SumOther_Sample.cpp
Last active May 4, 2024 20:56
Skip Summing Function
#include <iostream>
enum class SumMode
{
odd, // sum by 2n+1 indexing, n = 0
even // sum by 2n indexing, n = 0
};
template <SumMode M, typename T>
constexpr T sumOther (...) {
@DrkWithT
DrkWithT / VariadicIndex_Sample2.cpp
Created May 4, 2024 20:50
Argument Indexing Template
#include <iostream>
/**
@description Idx is the countdown to find the item in argv.
If the countdown is at least the size of the remaining args for a base case,
it would have reached 0 out of bounds. That condition would result in a defaulted value.
@note Only works with copyable types.
*/
// case 1: handle 1 arg