Skip to content

Instantly share code, notes, and snippets.

View othrayte's full-sized avatar

Adrian Cowan othrayte

  • Melbourne, Australia
View GitHub Profile
@othrayte
othrayte / Scroll.cpp
Created February 6, 2019 07:33
[WIP] Scroll - append only list, uses paging to allow lockless single writer / multiple reader with "random access" reads
#include <list>
#include <array>
#include <variant>
#include <memory>
#include <cassert>
template <class ...Fs>
struct overload : Fs... {
template <class ...Ts>
overload(Ts&& ...ts) : Fs{std::forward<Ts>(ts)}...
@othrayte
othrayte / sqaured_constants.cpp
Created April 11, 2018 07:42
Using c++ user defined literals to provide squared literal numbers
constexpr auto operator "" _²(long double x) {
return x*x;
}
constexpr unsigned long long int operator "" _²(unsigned long long int x) {
return x*x;
}
int main() {
return 4_²;
@othrayte
othrayte / local_ptr.cpp
Last active October 4, 2017 07:59
A pointer thats is always owned and alway present
#include <utility>
// A pointer thats is always owned and alway present (and valid if new returns a valid pointer)
// Should be useful if moving allocation of a member variable to the heap to enable use of forward declarations
template <typename T>
class local_ptr {
public:
template <typename... U>
local_ptr(U&&... args) : ptr(new T(std::forward<U>(args)...)) {}
@othrayte
othrayte / has_member.h
Last active September 8, 2017 15:54
Implementation of compile time checks for members with minimal boilerplate
#include <type_traits>
#include <list>
#include <vector>
#include <tuple>
template <typename T, template<typename> typename checker>
struct has_member
{
private:
template <typename U>