Skip to content

Instantly share code, notes, and snippets.

@sean-parent
sean-parent / test-value-assign
Created September 18, 2013 17:37
Test move assignment by value.
#include <iostream>
using namespace std;
struct annotate {
annotate() { cout << "annotate ctor" << endl; }
annotate(const annotate&) { cout << "annotate copy-ctor" << endl; }
annotate(annotate&&) noexcept { cout << "annotate move-ctor" << endl; }
annotate& operator=(const annotate&) { cout << "annotate assign" << endl; return *this; }
annotate& operator=(annotate&&) noexcept { cout << "annotate move-assign" << endl; return *this; }
@sean-parent
sean-parent / test-regular.cpp
Last active December 23, 2015 21:09
Snippet from asl to test regular and movable semantics.
namespace adobe {
// Precondition: x != T()
template <typename T>
void test_regular(const T& x)
{
assert(x != T());
T y = x; // Copy-construct
BOOST_CHECK(x == y);
@sean-parent
sean-parent / poly_any.cpp
Last active November 28, 2016 08:14
Intrusive value semantic polymorphism example.
#include <memory>
using namespace std;
template <typename C> // Concept base class
class any {
public:
template <typename T>
any(T x) : self_(new model<T>(move(x))) { }
#include <iostream>
#include <tuple>
#include <utility>
using namespace std;
template <typename F, typename T, size_t... I>
auto apply_(F f, T&& t, integer_sequence<size_t, I...>) {
return f(get<I>(t)...);
}
@sean-parent
sean-parent / main.cpp
Last active January 9, 2017 00:40
Playing with example of replacing mutex with serial queue.
#include <future>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <unordered_map>
#include <dispatch/dispatch.h>
using namespace std;
#include <tuple>
#include <iostream>
#include <cmath>
#include <stlab/future.hpp>
#include <stlab/channel.hpp>
using namespace stlab;
using namespace std;
using namespace std::chrono;
@sean-parent
sean-parent / channel_exp.hpp
Last active January 25, 2017 05:41
First cut at experimental channel design - no flow control yet (will be a future<void> returned by send).
#include <deque>
#include <memory>
#include <mutex>
#include <future>
#include <boost/optional.hpp>
#include <boost/thread/future.hpp>
namespace stlab {
class process {
#include <functional>
#include <future>
#include <memory>
#include <type_traits>
#include <dispatch/dispatch.h>
namespace stlab {
template <class Function, class... Args>
#include <functional>
#include <iostream>
#include <string>
template <class T>
class maybe {
std::aligned_storage_t<sizeof(T)> _value;
bool _has_value = false;
public:
This file has been truncated, but you can view the full file.
# 1 "/Users/sean-parent/Projects/github.com/sean-parent/scratch/scratch/main.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 421 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/Users/sean-parent/Projects/github.com/sean-parent/scratch/config.hpp" 1
# 2 "<built-in>" 2
# 1 "/Users/sean-parent/Projects/github.com/sean-parent/scratch/scratch/main.cpp" 2
# 1 "/Users/sean-parent/Projects/github.com/sean-parent/scratch/includes/stlab/concurrency/future.hpp" 1