This file contains 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 <array> | |
template<size_t NumOfStrings> | |
struct StringToInt | |
{ | |
std::array<std::string_view, NumOfStrings> strings{}; | |
constexpr StringToInt(auto&&...args) | |
{ | |
auto addEntry = [](auto&& collection, auto&& argument, size_t i) |
This file contains 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
// a blank struct to give an example of a failing concept | |
struct Something {}; | |
// a concept called Addable wich to satisfy requires that instances of T can use the + operator | |
template<typename T> | |
concept Addable = requires(T x) { x + x; }; | |
// a struct called Thing, which takes a type that is constrained by the 3 concepts after the 'requires' statement. | |
template<typename T> requires Addable<T> && std::copyable<T> && std::movable<T> | |
struct Thing |
This file contains 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 <array> | |
// simple template method that creates a std::array | |
template<typename...T> | |
auto make_array(T...data) -> std::array<std::tuple_element_t<0, std::tuple<T...>>, sizeof...(data)> | |
{ | |
return {data...}; | |
} |
This file contains 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
#pragma once | |
#include <list> | |
#include <unordered_map> | |
#include <optional> | |
#include <iostream> | |
#include <typeinfo> | |
template<typename K, typename V, size_t MaxEntries> | |
class LRUCache |
This file contains 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 <Windows.h> | |
#include <filesystem> | |
#include <array> | |
#include <string> | |
#include <string_view> | |
#include <vector> | |
#include <variant> | |
#include <Wmsdk.h> | |
#include <stdexcept> |
This file contains 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 "SomeClass.h" | |
#include <iostream> | |
// implementation | |
void SomeClass::doSomething() | |
{ | |
std::cout << "doing saomething" << std::endl; | |
} | |
int SomeClass::addTen(int from) |
This file contains 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
std::format is a nice simple way to do string interpolation in c++ | |
std::format("hello, {}!", "World); would print "`hello, World!`" for example. | |
I wanted to learn to create my own formatters so i could provide custom objects and have them printed nicely by just providing | |
it. There is not currently much documentation on the subject, but i managed to make it happen however one problem is the | |
std::formatter implementations will only take values, not references which means either you pass std::format a pointer to your object or | |
you allow it to take copies of your object. | |
## What if you dont want std::format to copy your object | |
Either you can define a formatter for a pointer of your object, or you can copy the code in this gist. |
This file contains 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
adding Handle.exe to the context menu: | |
Computer\HKEY_CLASSES_ROOT\Directory\shell\runas | |
HasLUASHield = "" | |
MUIVerb = "Query open handles" | |
Computer\HKEY_CLASSES_ROOT\Directory\shell\runas\Command | |
Default="powershell.exe -noexit -command handle.exe -u '%V'" | |
Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\runas | |
HasLUASHield = "" |
This file contains 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 <format> | |
#include <iterator> | |
class Thing | |
{ | |
public: | |
std::string s{ "some text" }; | |
}; |
This file contains 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
template<typename...Args> | |
std::string concat(Args...args) | |
{ | |
std::stringstream stream; | |
((stream << args), ...); | |
return std::move(stream.str()); | |
} | |
int main() | |
{ |
NewerOlder