Skip to content

Commit

Permalink
rename get_exception_ptr to as_exception_ptr
Browse files Browse the repository at this point in the history
 - some formatting
 - other pr comments
  • Loading branch information
Garcia6l20 committed Apr 15, 2021
1 parent 2461d80 commit e4cc6f6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
10 changes: 5 additions & 5 deletions include/unifex/any_sender_of.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
#pragma once

#include <unifex/any_unique.hpp>
#include <unifex/receiver_concepts.hpp>
#include <unifex/sender_concepts.hpp>
#include <unifex/as_exception_ptr.hpp>
#include <unifex/get_stop_token.hpp>
#include <unifex/inplace_stop_token.hpp>
#include <unifex/receiver_concepts.hpp>
#include <unifex/scheduler_concepts.hpp>
#include <unifex/sender_concepts.hpp>
#include <unifex/type_list.hpp>
#include <unifex/with_query_value.hpp>
#include <unifex/scheduler_concepts.hpp>
#include <unifex/get_exception_ptr.hpp>

#include <unifex/detail/prologue.hpp>

Expand Down Expand Up @@ -73,7 +73,7 @@ struct _rec_ref<CPOs, Values...>::type

template<typename Error>
void set_error(Error &&error) const noexcept {
unifex::set_error(*this, get_exception_ptr(std::forward<Error>(error)));
unifex::set_error(*this, as_exception_ptr(std::forward<Error>(error)));
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,46 @@
#include <unifex/type_traits.hpp>

#include <memory>
#include <system_error>

#include <unifex/detail/prologue.hpp>

namespace unifex
{
namespace _get_exception_ptr
namespace _as_exception_ptr
{
inline const struct _fn {
// forward std::exception_ptr
std::exception_ptr operator()(std::exception_ptr &&eptr) const noexcept {
return std::forward<std::exception_ptr>(eptr);
std::exception_ptr operator()(std::exception_ptr eptr) const noexcept {
return eptr;
}

// convert std::exception based types to std::exception_ptr
template(typename Exception)(
requires std::is_base_of_v<std::exception, Exception>)
template(typename Exception)(requires std::is_base_of_v<std::exception, Exception>)
std::exception_ptr
operator()(Exception &&ex) const noexcept {
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 is_tag_invocable_v<_fn, ErrorCode>)
std::exception_ptr operator()(ErrorCode &&error) const noexcept {
(requires tag_invocable<_fn, ErrorCode>) std::exception_ptr
operator()(ErrorCode&& error) const noexcept {
return tag_invoke(*this, std::forward<ErrorCode>(error));
}
} get_exception_ptr{};
} as_exception_ptr{};

// default std::error_code -> std::exception_ptr conversion
std::exception_ptr tag_invoke(tag_t<get_exception_ptr>, std::error_code &&error) noexcept {
std::exception_ptr
tag_invoke(tag_t<as_exception_ptr>, std::error_code&& error) noexcept {
return make_exception_ptr(
std::system_error{std::forward<std::error_code>(error)});
}

} // namespace _get_exception_ptr_cpo
} // namespace _as_exception_ptr

using _get_exception_ptr::get_exception_ptr;
using _as_exception_ptr::as_exception_ptr;
} // namespace unifex

#include <unifex/detail/epilogue.hpp>
2 changes: 1 addition & 1 deletion include/unifex/async_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include <unifex/config.hpp>
#include <unifex/as_exception_ptr.hpp>
#include <unifex/async_manual_reset_event.hpp>
#include <unifex/get_stop_token.hpp>
#include <unifex/inplace_stop_token.hpp>
Expand All @@ -27,7 +28,6 @@
#include <unifex/sequence.hpp>
#include <unifex/transform.hpp>
#include <unifex/type_traits.hpp>
#include <unifex/get_exception_ptr.hpp>

#include <atomic>
#include <memory>
Expand Down
6 changes: 3 additions & 3 deletions include/unifex/await_transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
# error "Coroutine support is required to use <unifex/await_transform.hpp>"
#endif

#include <unifex/as_exception_ptr.hpp>
#include <unifex/async_trace.hpp>
#include <unifex/coroutine_concepts.hpp>
#include <unifex/manual_lifetime.hpp>
#include <unifex/receiver_concepts.hpp>
#include <unifex/sender_concepts.hpp>
#include <unifex/type_traits.hpp>
#include <unifex/manual_lifetime.hpp>
#include <unifex/get_exception_ptr.hpp>

#include <cassert>
#include <exception>
Expand Down Expand Up @@ -110,7 +110,7 @@ struct _awaitable_base<Promise, Value>::type {

template <typename Error>
void set_error(Error &&error) && noexcept {
unifex::activate_union_member(result_->exception_, get_exception_ptr(std::forward<Error>(error)));
unifex::activate_union_member(result_->exception_, as_exception_ptr(std::forward<Error>(error)));
result_->state_ = _state::exception;
continuation_.resume();
}
Expand Down
10 changes: 5 additions & 5 deletions include/unifex/sync_wait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
#pragma once

#include <unifex/as_exception_ptr.hpp>
#include <unifex/bind_back.hpp>
#include <unifex/blocking.hpp>
#include <unifex/exception.hpp>
#include <unifex/manual_event_loop.hpp>
#include <unifex/manual_lifetime.hpp>
#include <unifex/scheduler_concepts.hpp>
#include <unifex/sender_concepts.hpp>
#include <unifex/blocking.hpp>
#include <unifex/with_query_value.hpp>
#include <unifex/bind_back.hpp>
#include <unifex/exception.hpp>
#include <unifex/get_exception_ptr.hpp>

#include <condition_variable>
#include <exception>
Expand Down Expand Up @@ -80,7 +80,7 @@ struct _receiver {

template <typename Error>
void set_error(Error &&e) && noexcept {
unifex::activate_union_member(promise_.exception_, get_exception_ptr(std::forward<Error>(e)));
unifex::activate_union_member(promise_.exception_, as_exception_ptr(std::forward<Error>(e)));
promise_.state_ = promise<T>::state::error;
signal_complete();
}
Expand Down
16 changes: 6 additions & 10 deletions test/get_exception_ptr_test.cpp → test/as_exception_ptr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@
* limitations under the License.
*/

#include <unifex/any_sender_of.hpp>
#include <unifex/get_exception_ptr.hpp>
#include <unifex/transform.hpp>
#include <unifex/sync_wait.hpp>
#include <unifex/just.hpp>
#include <unifex/as_exception_ptr.hpp>
#include <unifex/with_query_value.hpp>

#include <gtest/gtest.h>

using namespace unifex;

TEST(get_exception_ptr, error_code) {
TEST(as_exception_ptr, error_code) {
try {
std::rethrow_exception(
get_exception_ptr(std::make_error_code(std::errc::not_supported)));
as_exception_ptr(std::make_error_code(std::errc::not_supported)));
} catch (std::system_error& ex) {
EXPECT_EQ(ex.code(), std::errc::not_supported);
}
Expand All @@ -38,14 +34,14 @@ struct test_error {
int error_code;
};

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

TEST(get_exception_ptr, custom_error) {
TEST(as_exception_ptr, custom_error) {
try {
std::rethrow_exception(get_exception_ptr(test_error{42}));
std::rethrow_exception(as_exception_ptr(test_error{42}));
} catch (std::runtime_error& ex) {
EXPECT_EQ(ex.what(), std::string_view{"42"});
}
Expand Down

0 comments on commit e4cc6f6

Please sign in to comment.