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
-Wmissing-include-dirs | |
Warn if a user-supplied include directory does not exist | |
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 <chrono> | |
#include <iostream> | |
// Requires clang 17 or gcc 13 | |
int main() | |
{ | |
// UTC (system_clock is guaranteed to be UTC since C++20) | |
const auto now = std::chrono::system_clock::now(); | |
std::cout << "UTC time = " << now << '\n'; |
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
// Inspired by https://lib.rs/crates/bit-iter | |
#include <algorithm> | |
#include <bitset> | |
#include <concepts> | |
#include <limits> | |
template <typename T> | |
requires std::unsigned_integral<T> class BitIter { | |
public: |
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
#pragma once | |
#include <string> | |
#include <cxxabi.h> | |
template<typename T> | |
std::string demangleTemplateType() { | |
const auto typeName = typeid(T).name(); | |
const auto demangledName = abi::__cxa_demangle(typeName, nullptr, nullptr, nullptr); | |
const auto name = demangledName ? demangledName : typeName; |
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
#pragma once | |
#include <iterator> | |
// Inspired by / taken from: | |
// https://stackoverflow.com/questions/11328264/python-like-loop-enumeration-in-c | |
// https://www.reedbeta.com/blog/python-like-enumerate-in-cpp17/ | |
template<typename Iterable> | |
auto enumerate(Iterable&& iterable) { |
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
cmake_minimum_required(VERSION 3.17) | |
project(hello_rang) | |
set(CMAKE_CXX_STANDARD 11) | |
# Get library from Github | |
include(FetchContent) | |
FetchContent_Declare(rang GIT_REPOSITORY https://github.com/agauniyal/rang.git GIT_TAG v3.1.0) | |
FetchContent_MakeAvailable(rang) |
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
import colorama | |
colorama.init(autoreset = True) | |
print(colorama.Back.GREEN + colorama.Fore.RED + 'hello, colored world') |
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 <random> | |
template<typename T> | |
T random(T min = 0, T max = std::numeric_limits<T>::max()) { | |
static std::random_device randomDevice; | |
static std::mt19937 mersenneTwisterEngine(randomDevice()); | |
std::uniform_int_distribution<T> distribution{min, max}; | |
return distribution(mersenneTwisterEngine); | |
} |
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> | |
template<typename First, typename... Rest> | |
void trace(First&& first, Rest&& ... rest) { | |
if constexpr (sizeof...(rest) == 0) { | |
std::cout << std::forward<First>(first) << '\n'; | |
} else { | |
std::cout << std::forward<First>(first) << ' '; | |
trace(std::forward<Rest>(rest)...); | |
} |
NewerOlder