Skip to content

Commit

Permalink
add nothrow_tag_invokable concept
Browse files Browse the repository at this point in the history
 - update as_exception_ptr_test
  • Loading branch information
Garcia6l20 committed Apr 15, 2021
1 parent e4cc6f6 commit aca13cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/unifex/as_exception_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ namespace unifex
}

// convert std::exception based types to std::exception_ptr
template(typename Exception)(requires std::is_base_of_v<std::exception, Exception>)
std::exception_ptr
operator()(Exception&& ex) const noexcept {
template(typename Exception)
(requires std::is_base_of_v<std::exception, Exception>)
std::exception_ptr operator()(Exception&& ex) const noexcept {
return make_exception_ptr(std::forward<Exception>(ex));
}

// use customization point
// to resolve ErrorCode -> std::exception_ptr conversion
template(typename ErrorCode)
(requires tag_invocable<_fn, ErrorCode>) std::exception_ptr
operator()(ErrorCode&& error) const noexcept {
(requires nothrow_tag_invocable<_fn, ErrorCode>)
std::exception_ptr operator()(ErrorCode&& error) const noexcept {
return tag_invoke(*this, std::forward<ErrorCode>(error));
}
} as_exception_ptr{};
Expand Down
4 changes: 4 additions & 0 deletions include/unifex/tag_invoke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ namespace unifex {
(sizeof(_tag_invoke::try_tag_invoke<CPO, Args...>(0)) ==
sizeof(_tag_invoke::yes_type));

template <typename CPO, typename... Args>
UNIFEX_CONCEPT nothrow_tag_invocable =
(tag_invocable<CPO, Args...> && is_nothrow_tag_invocable_v<CPO, Args...>);

template <typename Fn>
using meta_tag_invoke_result =
meta_quote1_<tag_invoke_result_t>::bind_front<Fn>;
Expand Down
2 changes: 1 addition & 1 deletion test/as_exception_ptr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct test_error {
int error_code;
};

std::exception_ptr tag_invoke(tag_t<as_exception_ptr>, test_error&& error) {
std::exception_ptr tag_invoke(tag_t<as_exception_ptr>, test_error&& error) noexcept {
return std::make_exception_ptr(
std::runtime_error(std::to_string(std::forward<test_error>(error).error_code)));
}
Expand Down

0 comments on commit aca13cb

Please sign in to comment.