Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SANITIZERS := run
# SANITIZERS += asan # TODO: tsan msan
# endif

.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS)
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format unstage $(SANITIZERS) module build-module test-module

SYSROOT ?=
TOOLCHAIN ?=
Expand Down Expand Up @@ -134,20 +134,36 @@ build:
test: build
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure

module build-module:
cmake -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D CMAKE_SKIP_INSTALL_RULES=ON \
-D CMAKE_CXX_STANDARD=23 \
-D CMAKE_CXX_EXTENSIONS=ON \
-D CMAKE_CXX_STANDARD_REQUIRED=ON \
-D CMAKE_CXX_SCAN_FOR_MODULES=ON \
-D BEMAN_USE_MODULES=ON \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_COMPILER=$(CXX) --log-level=VERBOSE
cmake --build $(BUILD)

test-module: build-module
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure

install: test
cmake --install $(BUILD) --prefix /opt/local

CMakeUserPresets.json:: cmake/CMakeUserPresets.json
ln -s $< $@

# ==========================================================
release: CMakeUserPresets.json
appleclang-release llvm-release release: #-dk: I'm not sure why that is needed: CMakeUserPresets.json
cmake --preset $@ --log-level=TRACE # XXX --fresh
ln -fs $(BUILDROOT)/$@/compile_commands.json .
cmake --workflow --preset $@

# ==========================================================
debug: CMakeUserPresets.json
appleclang-debug llvm-debug debug: #-dk: I'm not sure why that is needed: CMakeUserPresets.json
cmake --preset $@ --log-level=TRACE # XXX --fresh
ln -fs $(BUILDROOT)build/$@/compile_commands.json .
cmake --workflow --preset $@
Expand Down
20 changes: 11 additions & 9 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,33 @@ if(PROJECT_IS_TOP_LEVEL)
endif()

set(EXAMPLES
stackoverflow
allocator
doc-just
doc-just_error
doc-just_stopped
inspect
intro-1-hello-world
intro-2-hello-async
intro-5-consumer
playground
sender-demo
when_all-cancel
stackoverflow
stop_token
stopping
allocator
intro-1-hello-world
intro-2-hello-async
intro-5-consumer
doc-just
doc-just_error
doc-just_stopped
when_all-cancel
)

if(BEMAN_USE_MODULES)
list(APPEND EXAMPLES modules) # modules.cpp
endif()
# set(EXAMPLES)

foreach(EXAMPLE ${EXAMPLES})
set(EXAMPLE_TARGET ${PROJECT_NAME}.${EXAMPLE})
add_executable(${EXAMPLE_TARGET})
target_sources(${EXAMPLE_TARGET} PRIVATE ${EXAMPLE}.cpp)
if(BEMAN_USE_MODULES)
# target_compile_definitions(${EXAMPLE_TARGET} PUBLIC BEMAN_HAS_MODULES)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman::execution)
else()
target_link_libraries(
Expand Down
9 changes: 8 additions & 1 deletion examples/allocator.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include <beman/execution/execution.hpp>
// examples/allocator.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <iostream>
#include <string>
#include <memory>
#include <memory_resource>
#include <span>
#include <vector>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif

namespace ex = beman::execution;

Expand Down
6 changes: 5 additions & 1 deletion examples/doc-just.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// examples/doc-just.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include <cassert>
#include <string>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif
namespace ex = beman::execution;
using namespace std::string_literals;

Expand Down
6 changes: 5 additions & 1 deletion examples/doc-just_error.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// examples/doc-just_error.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include <system_error>
#include <cassert>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif
namespace ex = beman::execution;

namespace {
Expand Down
7 changes: 5 additions & 2 deletions examples/doc-just_stopped.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// examples/doc-just_stopped.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include <system_error>
#include <cassert>
#include <iostream> //-dk:TODO remove
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif
namespace ex = beman::execution;

namespace {
Expand Down
126 changes: 124 additions & 2 deletions examples/inspect.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,138 @@
// examples/inspectc.pp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include "meta.hpp"
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <typeinfo>
#include <tuple>
#include <variant>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif

namespace ex = beman::execution;

// ----------------------------------------------------------------------------

namespace meta {
// The code in this namespace is a fairly basic way to print types. It can
// almost certainly be done better, in particular using reflection. However,
// that's beside the point of this example. The important part for the
// example is that meta::type<T>::name() yields a string representing the
// type T in some reasonable way
template <template <typename...> class, typename...>
struct list {
static auto name() { return "unknown-list"; }
};
template <>
struct list<::beman::execution::completion_signatures> {
static auto name() { return "ex::completion_signatures"; }
};

template <typename T>
struct type {
static auto name() { return typeid(T).name(); }
};
template <typename T>
struct type<T&> {
static auto name() { return typeid(T).name() + std::string("&"); }
};
template <typename T>
struct type<T&&> {
static auto name() { return typeid(T).name() + std::string("&&"); }
};
template <typename T>
struct type<T*> {
static auto name() { return typeid(T).name() + std::string("*"); }
};
template <typename T>
struct type<const T> {
static auto name() { return typeid(T).name() + std::string("const"); }
};
template <typename T>
struct type<volatile T> {
static auto name() { return typeid(T).name() + std::string("volatile"); }
};
template <typename T>
struct type<const volatile T> {
static auto name() { return typeid(T).name() + std::string("const volatile"); }
};
// NOLINTBEGIN(hicpp-avoid-c-arrays)
template <typename T, std::size_t N>
struct type<T[N]> {
static auto name() { return typeid(T).name() + std::string("[") + std::to_string(N) + "]"; }
};
template <typename T, std::size_t N>
struct type<T (&)[N]> {
static auto name() { return typeid(T).name() + std::string("(&)[") + std::to_string(N) + "]"; }
};
template <typename T, std::size_t N>
struct type<T (*)[N]> {
static auto name() { return typeid(T).name() + std::string("(*)[") + std::to_string(N) + "]"; }
};
// NOLINTEND(hicpp-avoid-c-arrays)

template <>
struct type<::beman::execution::set_value_t> {
static auto name() { return "ex::set_value_t"; }
};
template <>
struct type<::beman::execution::set_error_t> {
static auto name() { return "ex::set_error_t"; }
};
template <>
struct type<::beman::execution::set_stopped_t> {
static auto name() { return "ex::set_stopped_t"; }
};

template <typename T>
struct type<T()> {
static auto name() { return type<T>::name() + std::string("()"); }
};
template <typename T, typename A, typename... B>
struct type<T(A, B...)> {
static auto name() {
return type<T>::name() + std::string("(") + (type<A>::name() + ... + (std::string(", ") + type<B>::name())) +
")";
}
};
template <typename T>
struct type<T (*)()> {
static auto name() { return type<T>::name() + std::string("(*)()"); }
};
template <typename T, typename A, typename... B>
struct type<T (*)(A, B...)> {
static auto name() {
return type<T>::name() + std::string("(*)(") +
(type<A>::name() + ... + (std::string(", ") + type<B>::name())) + ")";
}
};

template <template <typename...> class L>
struct type<L<>> {
static auto name() { return list<L>::name() + std::string("<>"); }
};

template <template <typename...> class L, typename T, typename... S>
struct type<L<T, S...>> {
static auto name() {
return list<L>::name() + std::string("<") + (type<T>::name() + ... + (std::string(", ") + type<S>::name())) +
">";
}
};

template <typename T>
inline std::ostream& operator<<(std::ostream& out, const type<T>& t) {
return out << t.name();
}
} // namespace meta

// ----------------------------------------------------------------------------

namespace {
struct logger_t {
template <ex::sender Sndr, ex::receiver Rcvr, typename Log>
Expand Down
23 changes: 15 additions & 8 deletions examples/intro-1-hello-world.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// examples/intro-1-hello-world.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include <iostream>
#include <optional>
#include <string>
#include <tuple>
#include <variant>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif

namespace ex = ::beman::execution;
using namespace std::string_literals;
Expand All @@ -14,13 +20,14 @@ using namespace std::string_literals;

int main() {
// clang-format off
auto [result] = ex::sync_wait(
ex::when_all(
ex::just("hello, "s),
ex::just("world"s)
) | ex::then([](auto const& s1, auto const& s2) { return s1 + s2; })
).value_or(std::tuple(""s)
);
auto [result] =
ex::sync_wait(
ex::when_all(
ex::just("hello, "s),
ex::just("world"s)
) | ex::then([](auto const& s1, auto const& s2) { return s1 + s2; })
) .value_or(std::tuple(""s))
;
// clang-format on

std::cout << result << '\n';
Expand Down
10 changes: 8 additions & 2 deletions examples/intro-2-hello-async.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// examples/intro-2-hello-async.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include "intro-timer.hpp"
#include <chrono>
#include <iostream>
#include <queue>
#include <string>
#include <thread>
#include <tuple>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif
#include "intro-timer.hpp"

namespace ex = ::beman::execution;
using namespace std::string_literals;
Expand Down
6 changes: 5 additions & 1 deletion examples/intro-5-consumer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// examples/intro-5-consumer.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/execution.hpp>
#include <beman/execution/detail/suppress_push.hpp>
#include <chrono>
//-dk:TODO restore if that actually works #include <expected>
Expand All @@ -10,6 +9,11 @@
#include <tuple>
#include <variant>
#include <cinttypes>
#ifdef BEMAN_HAS_MODULES
import beman.execution;
#else
#include <beman/execution/execution.hpp>
#endif

namespace ex = ::beman::execution;
using namespace std::string_literals;
Expand Down
8 changes: 0 additions & 8 deletions examples/intro-timer.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// examples/intro-timer.hpp -*-C++-*-
// ----------------------------------------------------------------------------
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// ----------------------------------------------------------------------------

#ifndef INCLUDED_EXAMPLES_INTRO_TIMER
#define INCLUDED_EXAMPLES_INTRO_TIMER

#include <beman/execution/execution.hpp>
#include <chrono>
#include <queue>
#include <thread>
#include <tuple>

// ----------------------------------------------------------------------------

namespace intro {
Expand Down
Loading