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 <cstddef> | |
#include <span> | |
template <typename T> | |
constexpr std::span<T> allocate(std::size_t size) { | |
return {new T[size], 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
#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 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
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. |
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
# -*- coding: utf-8 -*- | |
""" rwlock.py | |
A class to implement read-write locks on top of the standard threading | |
library. | |
This is implemented with two mutexes (threading.Lock instances) as per this | |
wikipedia pseudocode: | |
https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock#Using_two_mutexes |
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
struct $ { | |
$ (*$)($*); | |
}; | |
$ d($* x) { | |
return *x; | |
} | |
int main() { | |
$ d = {::d}; |
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 <cstddef> | |
#include <concepts> | |
// version with static bounds on the dimensions | |
template <typename T, std::size_t... DIMS> | |
struct vec { | |
template <std::convertible_to<std::size_t>... Is> | |
requires (sizeof...(Is) == sizeof...(DIMS)) | |
T operator[](Is... indices) { return {}; } | |
}; |
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 <functional> | |
#include <mutex> | |
#include <shared_mutex> | |
#include <tuple> | |
#include <unordered_map> | |
#include <boost/container_hash/hash.hpp> | |
template <class> |
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
/* | |
* Written by Joshua Saxby ("saxbophone") 2023-03-14 -- saxbophone.com | |
* | |
* This demonstration program for how to derive max/min "safe" integers for | |
* conversion to and from floating point is hereby released into the public domain. | |
*/ | |
#include <limits> // numeric_limits | |
#include <type_traits> // make_signed |
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 <climits> | |
unsigned detect_overflow(unsigned x) { | |
auto old_x = x++; | |
if (old_x > x) { | |
std::cerr << "Overflow occurred: " << x - 1 << " -> " << x << std::endl; | |
} | |
return x; | |
} |
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
sudo apt-get install libx11-dev libxrandr-dev libudev-dev libfreetype-dev libopengl-dev libflac-dev libogg-dev libvorbis-dev libvorbisenc2 libvorbisfile3 libopenal-dev |