Skip to content

Commit

Permalink
Interoperability with boost::system::result
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Sep 17, 2024
1 parent 10dfe3c commit f3cb1f5
Show file tree
Hide file tree
Showing 18 changed files with 454 additions and 210 deletions.
42 changes: 21 additions & 21 deletions example/error_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
// not captured, only printed.

#include <boost/leaf.hpp>

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif

////////////////////////////////////////

#include <iostream>
#include <cstdlib>

Expand Down Expand Up @@ -125,24 +146,3 @@ int main()
} );
return 0;
}

////////////////////////////////////////

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what();
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif
42 changes: 21 additions & 21 deletions example/error_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
// recorded in a std::deque, rather than just printed in-place.

#include <boost/leaf.hpp>

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif

////////////////////////////////////////

#include <iostream>
#include <deque>
#include <cstdlib>
Expand Down Expand Up @@ -125,24 +146,3 @@ int main()
} );
return 0;
}

////////////////////////////////////////

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what();
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif
42 changes: 22 additions & 20 deletions example/lua_callback_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,32 @@
// This is a simple program that shows how to report error objects out of a
// C-callback, converting them to leaf::result<T> as soon as controlreaches C++.

#include <boost/leaf.hpp>

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif

////////////////////////////////////////

extern "C" {
#include "lua.h"
#include "lauxlib.h"
}
#include <boost/leaf.hpp>
#include <iostream>
#include <memory>
#include <stdlib.h>
Expand Down Expand Up @@ -153,22 +174,3 @@ int main()

return 0;
}

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what();
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif
2 changes: 1 addition & 1 deletion example/print_file/print_file_eh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// It reads a text file in a buffer and prints it to std::cout, using LEAF to
// handle errors. This version uses exception handling. The version that does
// not use exception handling is in print_file_result.cpp.
// not use exception handling is in print_file_leaf_result.cpp.

#include <boost/leaf.hpp>
#include <iostream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
// does use exception handling is in print_file_eh.cpp.

#include <boost/leaf.hpp>

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif

////////////////////////////////////////

#include <iostream>
#include <memory>
#include <stdio.h>
Expand Down Expand Up @@ -202,24 +223,3 @@ result<void> file_read( FILE & f, void * buf, std::size_t size )

return { };
}

////////////////////////////////////////

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what();
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif
44 changes: 22 additions & 22 deletions example/print_file/print_file_outcome_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,29 @@
// It reads a text file in a buffer and prints it to std::cout, using LEAF to
// handle errors. This version does not use exception handling.

#include <boost/outcome/std_result.hpp>
#include <boost/leaf.hpp>

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif

////////////////////////////////////////

#include <boost/outcome/std_result.hpp>
#include <iostream>
#include <memory>
#include <stdio.h>
Expand Down Expand Up @@ -210,24 +231,3 @@ result<void> file_read( FILE & f, void * buf, std::size_t size )

return outcome::success();
}

////////////////////////////////////////

#ifdef BOOST_LEAF_NO_EXCEPTIONS

namespace boost
{
[[noreturn]] void throw_exception( std::exception const & e )
{
std::cerr << "Terminating due to a C++ exception under BOOST_LEAF_NO_EXCEPTIONS: " << e.what();
std::terminate();
}

struct source_location;
[[noreturn]] void throw_exception( std::exception const & e, boost::source_location const & )
{
throw_exception(e);
}
}

#endif
Loading

0 comments on commit f3cb1f5

Please sign in to comment.