Skip to content

Instantly share code, notes, and snippets.

View mpark's full-sized avatar

Michael Park mpark

View GitHub Profile
@mpark
mpark / tuple.hpp
Last active August 24, 2017 06:15
A tuple that propagates implicit conversion properly
#include <iostream>
#include <type_traits>
#include <utility>
namespace mpark {
struct Implicit {};
struct Explicit {};
template <typename T>
#include <iostream>
#include <tuple>
#include <experimental/tuple>
#include <type_traits>
#include <utility>
// The same limitations apply to std::less if we wanted to figure out the winner
// of an overload resolution of `<`.
// it's a more general problem than for constructors.
@mpark
mpark / keybase.md
Last active February 19, 2018 07:47

Keybase proof

I hereby claim:

  • I am mpark on github.
  • I am mpark (https://keybase.io/mpark) on keybase.
  • I have a public key ASBfbLv7q9pb1eOovQGcdQL5wvbIPnFwRrkyTs14CJ-HGQo

To claim this, I am signing this object:

@mpark
mpark / visitor.cpp
Last active December 5, 2016 00:55
Visitor Pattern
class Cat;
class Dog;
class Animal {
public:
template <typename F>
static void visit(const F& f, const Animal& animal) {
animal.accept(Visitor<F>(f));
}
@mpark
mpark / type_traits.hpp
Last active December 15, 2015 10:12
C++14 `result_of` in VS 2015 Update 1
#include <type_traits>
namespace std {
namespace detail {
// A dummy tag type that indicates substitution failure. It should be hidden
// as best as possible, in this case it's just under the `detail` namespace.
struct fail;
#!/usr/bin/env python
import os
import subprocess
import tempfile
for n in xrange(100, 2001, 100):
with tempfile.NamedTemporaryFile(suffix='.cpp') as f:
f.write('#include <type_traits>\n')
f.write('#include <meta/meta.hpp>\n')
@mpark
mpark / sink.cc
Last active August 29, 2015 14:02
A discussion with @sean-parent regarding passing an sink arguments of arbitrary type T by value.
/**
* If we know that the sink argument is movable,
* then passing by value costs nothing if an rvalue is passed and
* only an extra move if an lvalue is passed.
* I agree that the extra move is no big deal here since it should be
* a constant time operation in most cases.
*
* So I like use cases such as:
*
* class TSink {