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 <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
// 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
/* | |
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
#include <span> | |
template<typename T> struct bad_span | |
{ | |
bad_span() : m_data(nullptr), m_size(0) {} | |
bad_span(std::initializer_list<T> value) : | |
m_data(value.begin()), | |
m_size(static_cast<uint32_t>(value.size())) | |
{ |
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
WINRT_EXPORT namespace winrt::param | |
{ | |
struct hstring | |
{ | |
#ifdef _MSC_VER | |
#pragma warning(suppress: 26495) | |
#endif | |
hstring() noexcept : m_handle(nullptr) {} | |
hstring(hstring const& values) = delete; | |
hstring& operator=(hstring const& values) = delete; |
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 <iostream> | |
#include <ifstream> | |
#include <string> | |
// 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; |
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
<?xml version="1.0" encoding="utf-8"?> | |
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220531.1\build\native\Microsoft.Windows.CppWinRT.props')" /> | |
<PropertyGroup Label="Globals"> | |
<CppWinRTOptimized>true</CppWinRTOptimized> | |
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> | |
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata> | |
<MinimalCoreWin>true</MinimalCoreWin> | |
<ProjectGuid>{86b1df74-0449-4ae4-a8ee-284912b2a7d1}</ProjectGuid> | |
<ProjectName>App2AppCore</ProjectName> |
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
// Tool to either invoke a method or read a field on a type. | |
class MyTypeName { | |
using TSelf = MyTypeName; | |
template<typename T> using func_or_field = std::variant< | |
T(TSelf::*)(), | |
T TSelf::*>; | |
template<typename T> auto invoke_func_or_field(func_or_field<T> const& fof) | |
{ |
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 <versionhelpers.h> | |
bool IsWindows10BuildOrGreater(uint16_t buildNumber) | |
{ | |
OSVERSIONINFOEXW osvi = { sizeof(osvi) }; | |
const auto conditionMask = VerSetConditionMask( | |
VerSetConditionMask( | |
VerSetConditionMask( | |
VerSetConditionMask( | |
0, VER_MAJORVERSION, VER_GREATER_EQUAL), |