Skip to content

Instantly share code, notes, and snippets.

View ericniebler's full-sized avatar

Eric Niebler ericniebler

View GitHub Profile
@ericniebler
ericniebler / slide.cpp
Last active May 4, 2016 04:53
a counted range, and slide working with counted and non-counted iterators
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <range/v3/range.hpp>
using namespace ranges;
template<typename It>
class counted_range : public range_facade<counted_range<It>>
{
@ericniebler
ericniebler / insertion_sort.cpp
Last active August 29, 2015 14:07
insertion_sort benchmark for counted iterables
#include <chrono>
#include <iostream>
// From https://github.com/ericniebler/range-v3 :
#include <range/v3/range.hpp>
class timer
{
private:
std::chrono::high_resolution_clock::time_point start_;
public:
@ericniebler
ericniebler / constexpr_string.cpp
Created December 10, 2016 04:27
An almost perfect design for a hybrid constexpr/runtime string
// Copyright Eric Niebler 2016
#include <cstddef>
#include <cstdio>
#include <cstdint>
#include <cstring>
#include <utility>
#include <type_traits>
#define REQUIRES(X) \
#include <type_traits>
template<int I> struct priority_tag : priority_tag<I - 1> {};
template<> struct priority_tag<0> {};
// Function types here:
template<typename T>
char (&is_function_impl_(priority_tag<0>))[1];
// Array types here:
@ericniebler
ericniebler / reference_wrapper.hpp
Last active June 28, 2017 23:37
reference_wrapper minus the nasty implicit conversion sequence from rvalues
#include <type_traits>
#include <functional>
template <class T, class...As>
concept bool Constructible =
std::is_constructible_v<T, As...>;
template <class A, class B>
concept bool Same = __is_same_as(A, B);
@ericniebler
ericniebler / merge2std.cpp
Last active June 1, 2018 17:51
iterator traits and tags redesign for merging the Ranges TS
// Copyright 2018-present Eric Niebler
// Copyright 2018-present Facebook, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@ericniebler
ericniebler / executor_compromise_the_return.md
Last active September 7, 2018 18:01 — forked from LeeHowes/executor_compromise_the_return.md
A second executor compromise

A lazy simplification of P0443

Summary

This paper seeks to add support for lazy task creation and deferred execution to P0443, while also simplifying the fundamental concepts involved in asynchronous execution. It seeks to do this as a minimal set of diffs to P0443. It achieves this by replacing P0443's six Executor::*execute() member functions with two lazy task constructors that each return a lazy Future-like type known as a "Sender". Work is actually enqueued by calling submit() on a Sender.

Background

P0443 presents a unified abstraction for agents of asynchronous execution. It is the result of a long collaboration between experts from many subdomains of concurrent and parallel execution, and achieved consensus within SG1 and, to some degree, LEWG. Although there were known gaps in the abstraction, there were papers in flight to address them, and for all intents and purposes P0443 seemed on-target for a TS or, possibly even C++20.

-- [range-v3]: C++ std=2a
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/eniebler/Code/range-build-gcc-8.2
eniebler-mbp:range-build-gcc-8.2 eniebler$ cmake .
-- [range-v3]: C++ std=2a
[master 47b8d922] 0.5.0
3 files changed, 21 insertions(+), 2 deletions(-)
-- Exporting conanfile for new version
WARN: replace_in_file didn't find pattern '[plugins]' in '/Users/eniebler/.conan/conan.conf' file.
@ericniebler
ericniebler / execution.h
Last active January 20, 2020 22:39
Partial header <execution> for P0443R12
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ericniebler
ericniebler / tag_invoke.hpp
Created October 12, 2020 21:21
Simple implementation of the tag_invoke customization point
#include <utility>
#include <type_traits>
namespace _tag_invoke {
void tag_invoke();
struct _fn {
template <typename CPO, typename... Args>
constexpr auto operator()(CPO cpo, Args&&... args) const
noexcept(noexcept(tag_invoke((CPO &&) cpo, (Args &&) args...)))