beman.task

beman.task: Beman Library Implementation of task (P3552)

Library StatusStandard TargetCoveragehttps://godbolt.org/z/anYY59nYd[Compiler Explorer Example]

beman::execution::task<T, Context> is a class template which is used as the the type of coroutine tasks. The corresponding objects are senders. The first template argument (T) defines the result type which becomes a set_value_t(T) completion signatures. The second template argument (Context) provides a way to configure the behavior of the coroutine. By default it can be left alone.

License

beman.task is licensed under the Apache License v2.0 with LLVM Exceptions.

Usage

The following code snippet shows a basic use of beman::task::task using sender/receiver facilities to implement version of hello, world:

#include <beman/task.hpp>
#include <beman/execution.hpp>
#include <iostream>

namespace ex = beman::execution;
namespace ly = beman::task;

int main() {
    return std::get<0>(*ex::sync_wait([]->ex::task<int> {
        std::cout << "Hello, world!\n";
        co_return co_await ex::just(0);
    }()));
}

Full runnable examples can be found in examples/ (e.g., ./examples/hello.cpp). For some explanation see ./docs/examples.md.

Help Welcome

There are plenty of things which need to be done. See the contributions page for some ideas how to contribute. The resources page contains some links for general information about coroutines.

Dependencies

Build Environment

This project requires at least the following to build:

  • A C compiler that conforms to the C23 standard or greater

  • CMake 3.30 or later

  • (Test Only) GoogleTest

  • beman::execution (auto-fetched via CMake FetchContent)

You can disable building tests by setting CMake option BEMAN_TASK_BUILD_TESTS to OFF when configuring the project.

You can disable building examples by setting CMake option BEMAN_TASK_BUILD_EXAMPLES to OFF when configuring the project.

Building beman.task

Supported Platforms

Compiler Version C++ Standards Standard Library

GCC

15-14

C26, C23

libstdc++

Clang

21-19

C26, C23

libc++

MSVC

latest

C++23

MSVC STL

How to build beman.task

This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static libbeman.task.a library, ready to package with its headers:

# Build beman.task.
$ cmake --workflow --preset gcc-debug
$ cmake --workflow --preset gcc-release

# Install beman.task into your system.
$ cmake --install build/gcc-release/ --prefix /opt/beman.task/
-- Install configuration: "RelWithDebInfo"
-- Installing: /opt/beman.task/lib/libbeman.task.a
-- Installing: /opt/beman.task/include/beman/task/task.hpp
[...]

$ tree /opt/beman.task/
/opt/beman.task/
├── include
│   └── beman
│       └── task
│           ├── detail
│           │   ├── affine_on.hpp
│           │   ├── ...
│           │   ├── task.hpp
│           │   └── with_error.hpp
│           └── task.hpp
└── lib
    ├── cmake
    │   └── beman
    │       └── task
    │           └── BemanTaskConfig.cmake
    └── libbeman.task.a

9 directories, 26 files

Contributing

Please do! Issues and pull requests are appreciated.