Skip to content

Instantly share code, notes, and snippets.

View ericniebler's full-sized avatar

Eric Niebler ericniebler

View GitHub Profile
@ericniebler
ericniebler / cpo.hpp
Last active February 4, 2024 02:04
portability customization point macros
/*
* Copyright (c) 2024 NVIDIA Corporation
*
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
@ericniebler
ericniebler / basic_any.cpp
Last active February 3, 2024 02:18
a utility for creating type-erasing wrappers like Folly.Poly
#include <cstdio>
#include <memory>
#include <stdexcept>
#include <stdexec/__detail/__meta.hpp>
#include <typeinfo>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
@ericniebler
ericniebler / execution-domain-fun.cpp
Created November 8, 2023 08:24
A demonstration of how execution domains ensure the correct sender algorithm implementation is selected
#include <iostream>
#include "stdexec/execution.hpp"
#include "exec/env.hpp"
namespace ex = stdexec;
using namespace std::literals;
template <class Sender, class Tag>
concept sender_for =
ex::sender<Sender> && std::same_as<ex::tag_of_t<Sender>, Tag>;
@ericniebler
ericniebler / Widget.hpp
Last active May 26, 2023 22:39
A demonstration of how to implement a forward and backward ABI compatible class type
#pragma once
#include <memory>
#include <cstdint>
namespace library {
namespace detail {
namespace v1 {
@ericniebler
ericniebler / arbitrary-cpo-forwarding.cpp
Created November 18, 2022 20:23
An example of how arbitrarily-named customization points can be generically forwarded
#if defined(__has_feature)
#if __has_feature(__cpp_static_call_operator)
#define STATIC_CALL_OPERATOR(...) static __VA_ARGS__ operator() STATIC_CALL_OPERATOR_
#define STATIC_CALL_OPERATOR_(...) (__VA_ARGS__)
#endif
#endif
#ifndef STATIC_CALL_OPERATOR
#define STATIC_CALL_OPERATOR(...) __VA_ARGS__ operator() STATIC_CALL_OPERATOR_
@ericniebler
ericniebler / lambda-tuple.cpp
Last active September 30, 2023 15:01
Build a C++ tuple out of C++20 lambda functions
#include <concepts>
#include <type_traits>
#include <utility>
namespace stdlite {
template <class Tp>
Tp&& _declval() noexcept;
struct _cp {
@ericniebler
ericniebler / toy_executors.hpp
Last active June 9, 2022 22:36
A toy implementation of P2300, the std::execution proposal, for teaching purposes
/*
* Copyright 2022 NVIDIA Corporation
*
* 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 / task.hpp
Last active January 20, 2021 23:50
Simple coroutine task<> type
#include <cassert>
#include <mutex>
#include <condition_variable>
#include <variant>
#include <utility>
#include <exception>
#if __has_include(<coroutine>)
#include <coroutine>
namespace coro = std;
@ericniebler
ericniebler / sync_wait.hpp
Last active December 21, 2021 03:01
sync_wait function for an awaitable task type
#include <cassert>
#include <mutex>
#include <condition_variable>
#include <variant>
#include <utility>
#include <exception>
#if __has_include(<coroutine>)
#include <coroutine>
namespace coro = std;
@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...)))