-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- async_destroy CPO - returns a `unique_ptr`-like object
- Loading branch information
1 parent
fb13829
commit 434ad64
Showing
24 changed files
with
2,059 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* 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 | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <unifex/just.hpp> | ||
#include <unifex/tag_invoke.hpp> | ||
|
||
namespace unifex { | ||
namespace _async_destroy { | ||
|
||
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( | ||
"Can't async_destroy an object with no async_destroy customization; add " | ||
"a no-op if that's what's intended.")]] 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 _async_destroy | ||
using _async_destroy::async_destroy; | ||
} // namespace unifex |
Oops, something went wrong.