This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Here's some powershell to run to generate this type | |
cls | |
$typeList = @( | |
"UInt8", | |
"UInt16", | |
"UInt32", | |
"UInt64", | |
# "Int8", -- not a valid type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Opens a file by path name. Assumes the file is UTF-8 encoded. If the file | |
// has a BOM, it'll be skipped so the first access to the file is positioned | |
// correctly. | |
std::wifstream open_utf8_with_maybe_bom(std::filesystem::path const& path) | |
{ | |
std::wifstream ss; | |
ss.imbue(std::locale(".utf-8")); | |
ss.open(path); | |
if (ss.good() && (ss.peek() == 0xFEFF)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mutex> | |
struct guid { uint64_t id[2]; }; | |
template<typename T> guid const& guid_of() | |
{ | |
return T::iid; | |
} | |
struct IUnknown { | |
virtual uint32_t AddRef() = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <algorithm> | |
#include <string_view> | |
// From https://medium.com/@vgasparyan1995/compile-time-merge-sort-c-bb0ace62cc23 | |
constexpr auto sort(const auto& arr) | |
{ | |
auto result = arr; | |
auto sortless = [](auto const& a, auto const& b) { return a.first < b.first; }; | |
std::sort(std::begin(result), std::end(result), sortless); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wil/com.h> | |
// Wraps a type like IEnumIUknown and exposes it as a forward iterator, | |
// or like IEnumIDList and exposes it as a forward iterator of type TStoredType. | |
// The IEnumType must have the following methods: | |
// HRESULT Next(ULONG celt, T* rgelt, ULONG* pceltFetched) | |
template <typename IEnumType, typename TStoredType> | |
struct iterator | |
{ | |
wil::com_ptr<IEnumType> m_enum{}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
#include <functional> | |
// Given a container that supports "begin(c)" / "end(c)", uses std::transform plus a | |
// provided transmutor function to produce an output vector of the results. The | |
// type of the vector returned is derived from the return type of the transmutor | |
// operation. | |
template<typename Z, typename Q> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <random> | |
#include <string> | |
#include <vector> | |
#include <span> | |
#include <winrt/windows.storage.streams.h> | |
#include <winrt/windows.security.cryptography.h> | |
#include <winrt/windows.security.cryptography.core.h> | |
#include <winrt/windows.security.cryptography.certificates.h> | |
namespace winrt { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tuple> | |
#include <iostream> | |
#include <algorithm> | |
#include <string_view> | |
#include <array> | |
#include <stdexcept> | |
#include <optional> | |
// This is a bijection lookup helper that given an array of pairs finds the key or | |
// the value. The keys should be sorted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is replacement for std::format on systems that don't have std::locale support, | |
// but do have std::to_chars locale invariant. | |
template <typename... Args> | |
std::string myformat(std::format_string<Args...> fmt, Args&&... args) | |
{ | |
std::string output; | |
auto formatArgStore = std::make_format_args(args...); | |
auto formatArgs = std::format_args(formatArgStore); | |
std::string_view fmtString = fmt.get(); | |
int nextIndex = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <span> | |
#include <variant> | |
#include <memory> | |
template<typename T, int internal = 25> struct small_vector_optimization : std::span<T const> | |
{ | |
small_vector_optimization(std::span<T const> src) | |
{ | |
if (src.size() <= internal) |