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 <string> | |
#pragma pack(push, 1) | |
struct Chunk { | |
char32_t first : 21; | |
char32_t second : 21; | |
char32_t third : 21; | |
operator std::u32string() const { | |
return {first, second, third}; | |
} |
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
time CC=gcc-10.2 CXX=g++-10.2 cmake -S ../llvm-project/llvm -B build -DCMAKE_BUILD_TYPE=Release | |
-DLLVM_PARALLEL_COMPILE_JOBS=4 -DLLVM_PARALLEL_LINK_JOBS=1 -DLLVM_ENABLE_RUNTIMES="" -DLLVM_ENABLE_PROJECTS=clang | |
-DLLVM_CCACHE_BUILD=ON -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_LTO=On -DLLVM_ENABLE_RTTI=ON -DLLVM_INCLUDE_TESTS=OFF | |
-DLLVM_LINK_LLVM_DYLIB=ON -DCMAKE_C_FLAGS_RELEASE="-O3 -march=native" -DCMAKE_CXX_FLAGS_RELEASE="-O3 -march=native" | |
-DLLVM_ENABLE_LIBXML2=OFF -DCMAKE_CXX_STANDARD=20 |
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 <regex> | |
#include <string> | |
int main() { | |
std::regex find_undefs{"(?:#undef\\s+)([_A-z][_0-9A-z]*)"}; | |
std::cout << std::regex_replace("#undef _1FOO_BAR_BAZ1234_", find_undefs, "#cmakedefine $1 1") << std::endl; | |
} |
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 <mutex> | |
#include <shared_mutex> | |
#include <type_traits> | |
// TOOD: reïmplement all methods non-inline so the prototype is nice and readable | |
template <typename T> | |
class Seizable { | |
public: | |
// TODO: change to std::shared_timed_mutex and add additional time-based locking methods |
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
git ls-remote --tags --refs --sort='v:refname' https://github.com/llvm/llvm-project.git | while read -r line; do | |
sha=$(echo $line | awk '{print substr($1, 1, 8)}'); | |
ref=$(echo $line | awk '{print $2}'); | |
b91=$(echo $sha | xxd -r -p | base91); | |
echo "$sha = $b91 ($ref)"; | |
done |
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 <cstddef> | |
#include <numeric> | |
#include <random> | |
#include <stdexcept> | |
#include <vector> | |
class LotteryMachine { | |
public: | |
LotteryMachine(std::size_t number_of_balls) |
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 <cstddef> | |
#include <span> | |
template <typename T> | |
constexpr std::span<T> allocate(std::size_t size) { | |
return {new T[size], size}; | |
} |
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
/* client.c */ | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#define BUF_SIZE 500 |
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 <cstddef> | |
#include <span> | |
constexpr std::size_t populate(std::span<int> data) { | |
std::size_t w = 0; | |
for (; w < 1000; ++w) { | |
// this should maybe be a bounds-check instead, but in theory | |
// this should only be called on containers that are exactly |
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
class StringView: | |
""" | |
StringView implementation using minimal copying with maximum use of | |
reference semantics. Creating a sub-view of an existing StringView using | |
either object slicing or constructing one from another will reüse the same | |
source string object, using a reference rather than a copy. | |
The contents() method can similarly be used to get an iterator (Generator) | |
to access the view contents sequentially without putting it all in memory | |
at once. | |
A brand new string object is only created if the StringView is cast to str. |
NewerOlder