2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-19 04:22:08 +00:00

tweaks, removed throw_exception.hpp

This commit is contained in:
Emil Dotchevski
2018-10-26 09:23:38 -07:00
parent 94f8e813df
commit 34a7717f8b
9 changed files with 55 additions and 71 deletions

View File

@@ -807,6 +807,24 @@ namespace boost [ namespace leaf {
----
====
Objects of class `error_capture` are similar to `<<expect,expect>>` instances in that they contain `e_` objects and can be examined by (their own overloads of) `peek` and `handle_error`. However, unlike `expect` objects, `error_capture` objects:
* are immutable;
* are allocated on the heap;
* associate all of their `e_` objects with exactly one `error` value;
* when probed with `peek`/`handle_error`, the lookup is dynamic;
* define `noexcept` copy/move/assignment operations.
The default constructor can be used to initialize an empty `error_capture`. Use `<<capture,capture>>` to capture all `e_` objects associated with a given `error` value from a given `expect` object.
[NOTE]
--
Typical use of `error_capture` objects is to transport `e_` objects across threads, however they are rarely used directly. Instead:
* With exception handling, use `<<capture_exception,capture_exception>>` / `<<get,get>>`;
* Without exception handling, simply return a <<result::capture,captured>> `result<T>` from a worker thread.
--
'''
==== `error_capture()`

View File

@@ -11,4 +11,3 @@
#include <boost/leaf/exception.hpp>
#include <boost/leaf/expect.hpp>
#include <boost/leaf/result.hpp>
#include <boost/leaf/throw_exception.hpp>

View File

@@ -8,7 +8,6 @@
#define UUID_C86E4C4ED0F011E8BB777EB8A659E189
#include <boost/leaf/error.hpp>
#include <boost/leaf/throw_exception.hpp>
#include <boost/leaf/detail/print.hpp>
#include <tuple>

View File

@@ -10,12 +10,48 @@
#include <boost/leaf/expect.hpp>
#include <exception>
#define LEAF_THROW(e) ::boost::leaf::throw_exception(e,LEAF_SOURCE_LOCATION)
namespace
boost
{
namespace
leaf
{
namespace
leaf_detail
{
inline void enforce_std_exception( std::exception const & ) { }
template <class Ex>
class
exception:
public Ex,
public error
{
public:
exception( Ex && ex, error && e ) noexcept:
Ex(std::move(ex)),
error(std::move(e))
{
enforce_std_exception(*this);
}
};
}
template <class... E,class Ex>
[[noreturn]]
void
throw_exception( Ex && ex, E && ... e )
{
throw leaf_detail::exception<Ex>(std::move(ex),error(std::move(e)...));
}
template <class... E,class Ex>
[[noreturn]]
void
throw_exception( Ex && ex, error const & err, E && ... e )
{
throw leaf_detail::exception<Ex>(std::move(ex),err.propagate(std::move(e)...));
}
////////////////////////////////////////
template <class P,class... E>
decltype(P::value) const *
peek( expect<E...> const & exp, std::exception const & e ) noexcept

View File

@@ -7,7 +7,7 @@
#ifndef UUID_AFBBD676B2FF11E8984C7976AE35F1A2
#define UUID_AFBBD676B2FF11E8984C7976AE35F1A2
#include <boost/leaf/throw_exception.hpp>
#include <boost/leaf/error.hpp>
#include <boost/leaf/detail/print.hpp>
#include <tuple>

View File

@@ -1,57 +0,0 @@
//Copyright (c) 2018 Emil Dotchevski
//Copyright (c) 2018 Second Spectrum, Inc.
//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 UUID_0DBBFB5AD3FA11E89F9D20E3C82C3C47
#define UUID_0DBBFB5AD3FA11E89F9D20E3C82C3C47
#include <boost/leaf/error.hpp>
#include <exception>
#define LEAF_THROW(e) ::boost::leaf::throw_exception(e,LEAF_SOURCE_LOCATION)
namespace
boost
{
namespace
leaf
{
namespace
leaf_detail
{
inline void enforce_std_exception( std::exception const & ) { }
template <class Ex>
class
exception:
public Ex,
public error
{
public:
exception( Ex && ex, error && e ) noexcept:
Ex(std::move(ex)),
error(std::move(e))
{
enforce_std_exception(*this);
}
};
}
template <class... E,class Ex>
[[noreturn]]
void
throw_exception( Ex && ex, E && ... e )
{
throw leaf_detail::exception<Ex>(std::move(ex),error(std::move(e)...));
}
template <class... E,class Ex>
[[noreturn]]
void
throw_exception( Ex && ex, error const & err, E && ... e )
{
throw leaf_detail::exception<Ex>(std::move(ex),err.propagate(std::move(e)...));
}
}
}
#endif

View File

@@ -31,7 +31,6 @@ tests = [
'_hpp_exception_test',
'_hpp_expect_test',
'_hpp_result_test',
'_hpp_throw_exception_test',
'basic_test',
'diagnostic_print_test',
'error_capture_test',

View File

@@ -22,7 +22,6 @@ run _hpp_exception_capture_test.cpp ;
run _hpp_exception_test.cpp ;
run _hpp_expect_test.cpp ;
run _hpp_result_test.cpp ;
run _hpp_throw_exception_test.cpp ;
run basic_test.cpp ;
run diagnostic_print_test.cpp ;
run error_capture_test.cpp ;

View File

@@ -1,9 +0,0 @@
//Copyright (c) 2018 Emil Dotchevski
//Copyright (c) 2018 Second Spectrum, Inc.
//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/leaf/throw_exception.hpp>
#include <boost/leaf/throw_exception.hpp>
int main() { return 0; }