Skip to content

Instantly share code, notes, and snippets.

teplate <class T>
auto split(future<T>&&) -> pair<future<T>, future<T>>;
// Q: Is the only way to attach a continuation to spawn/await?
class application {
//...
future<document> _document;
vector<future<void>> _pending; // async scope

The use of "valid but unspecified" as a guarantee is useless and damaging. Consider std::list<>. A guarantee of std::list<> is that on move the iterators are not invalidated (different use of valid), except for the end iterator. The end iterator frequently points directly to an empty terminal node directly in the local instance so moving a list invalidates the end iterator. Invalidation can be a source of bugs so a library implementor decided their implementation would strengthen the guarantee by ensuring that the end iterator was valid even with a move. To do so, they heap-allocate the terminal node for each list.

If you move-construct this list, the rhs argument must be "valid but unspecified". To achieve that, an end node must be allocated in the rhs. Now the move constructor is not noexcept. Not having a noexcept move constructor is problematic because it makes it impossible to get robust transactional behavior to restore a system after a throw. Trying to complete a transaction by moving in the r

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
#include <functional>
#include <iostream>
#include <string>
template <class T>
class maybe {
std::aligned_storage_t<sizeof(T)> _value;
bool _has_value = false;
public:
#include <functional>
#include <future>
#include <memory>
#include <type_traits>
#include <dispatch/dispatch.h>
namespace stlab {
template <class Function, class... Args>
@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 <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 / 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 <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 / 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))) { }