-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
820f9c3
commit b465193
Showing
6 changed files
with
99 additions
and
4 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
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,65 @@ | ||
// | ||
// Copyright (c) 2023 Klemens Morgenstern ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#ifndef BOOST_COBALT_NOTHROW_HPP | ||
#define BOOST_COBALT_NOTHROW_HPP | ||
|
||
#include <boost/cobalt/config.hpp> | ||
|
||
#include <boost/system/result.hpp> | ||
#include <boost/system/error_code.hpp> | ||
#include <boost/system/errc.hpp> | ||
|
||
#include <coroutine> | ||
|
||
namespace boost::cobalt | ||
{ | ||
|
||
template<typename Handle> | ||
struct nothrow : boost::system::result<Handle> | ||
{ | ||
nothrow(Handle && h) : boost::system::result<Handle>(boost::system::in_place_value, std::move(h)) {} | ||
nothrow() : boost::system::result<Handle>(boost::system::in_place_error, | ||
make_error_code(boost::system::errc::not_enough_memory)) | ||
{} | ||
}; | ||
|
||
} | ||
|
||
template<typename Handle, typename ... Args> | ||
struct std::coroutine_traits<boost::cobalt::nothrow<Handle>, Args...> | ||
{ | ||
struct promise_type : std::coroutine_traits<Handle, Args...>::promise_type | ||
{ | ||
static void* operator new(std::size_t sz) noexcept | ||
{ | ||
return ::operator new(sz, std::nothrow); | ||
} | ||
|
||
static void operator delete(void * raw, const std::size_t size) noexcept | ||
{ | ||
#if defined(__cpp_sized_deallocation) | ||
::operator delete(raw, size); | ||
#else | ||
::operator delete(raw); | ||
#endif | ||
} | ||
|
||
boost::cobalt::nothrow<Handle> get_return_object() | ||
{ | ||
return std::coroutine_traits<Handle, Args...>::promise_type::get_return_object(); | ||
} | ||
|
||
static boost::cobalt::nothrow<Handle> get_return_object_on_allocation_failure() | ||
{ | ||
return {}; | ||
} | ||
|
||
}; | ||
}; | ||
|
||
#endif //BOOST_COBALT_NOTHROW_HPP |
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,27 @@ | ||
// | ||
// Copyright (c) 2024 Klemens Morgenstern ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#include <boost/cobalt/nothrow.hpp> | ||
|
||
#include <boost/cobalt/task.hpp> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include "test.hpp" | ||
|
||
boost::cobalt::nothrow<boost::cobalt::task<void>> p1() {co_return ;} | ||
boost::cobalt::nothrow<boost::cobalt::task<void>> p2() | ||
{ | ||
volatile char data[1000000000000ull]; | ||
co_return ; | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(nothrow_) | ||
{ | ||
BOOST_CHECK(p1().has_value()); | ||
BOOST_CHECK(p2().has_error()); | ||
} | ||
|