Skip to content

Commit

Permalink
introduce unifex::async_resource
Browse files Browse the repository at this point in the history
- async_destroy CPO
- returns a ptr-like object
- sample tests
  • Loading branch information
janondrusek committed Nov 4, 2022
1 parent fa922b0 commit 1161dfd
Show file tree
Hide file tree
Showing 6 changed files with 789 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/unifex/async_destroy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.

#pragma once

#include <unifex/just.hpp>
#include <unifex/tag_invoke.hpp>

namespace unifex {
// meant for unifex upstream, different naming convention
// @nolint(readability-identifier-naming)

inline constexpr struct _destroy_fn {
private:
template <typename Resource>
static auto try_invoke_member(Resource& resource, int) noexcept
-> decltype(resource.destroy()) {
return resource.destroy();
}

template <typename Resource>
[[deprecated("noop async_destroy")]] static auto
try_invoke_member(Resource&, double) noexcept {
return unifex::just();
}

public:
template <typename Resource>
constexpr auto operator()(Resource& resource) const noexcept {
if constexpr (unifex::tag_invocable<_destroy_fn, Resource&>) {
return unifex::tag_invoke(_destroy_fn{}, resource);
} else {
return try_invoke_member(resource, 1);
}
}
} async_destroy{};
} // namespace unifex
Loading

0 comments on commit 1161dfd

Please sign in to comment.