Skip to content

Instantly share code, notes, and snippets.

View philsquared's full-sized avatar

Phil Nash philsquared

View GitHub Profile
// Define an optional chaining pipeline operator
operator infix |> { associativity left }
func |> <T, U>(t: T?, f: (T) -> U? ) -> U? {
if let t1 = t { return f( t1 ) }
else { return nil }
}
// some dummy classes and functions to chain together
class C { let x = 7 }
class B { }
struct MaxUsage { int memory, disk; };
TEST_CASE( "KeyValueBuffer disk memory usage" )
{
using namespace Catch::Generators;
MaxUsage params[] = {
{ 1, 2 },
{ 1, 1024 },
{ 8, 1024 },
@philsquared
philsquared / C++ Extension Methods
Created April 11, 2013 23:45
How to write the "left arrow operator" to enable extension methods in C++
#include <cassert>
#include <iostream>
template<typename T, typename R=void>
struct ExtMethod {
ExtMethod& operator - () {
return *this;
}
template<typename U>