Skip to content

Instantly share code, notes, and snippets.

View ericniebler's full-sized avatar

Eric Niebler ericniebler

View GitHub Profile
@ericniebler
ericniebler / enmeta.hpp
Last active October 4, 2024 19:36
meta-programming library
/*
* Copyright (c) 2021-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 / metasort.cpp
Created May 5, 2024 22:26
C++17 code to sort a list of types alphabetically at compile-time
#include <cstddef>
#include <utility>
#include <array>
#include <cstdio>
#include <string_view>
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wnon-template-friend"
@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_senders.hpp
Last active November 7, 2024 07:07
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;