Skip to content

Commit

Permalink
Excluding things that require C++17 from C++11/14 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Sep 22, 2024
1 parent 5ae9f2a commit 72578fa
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 45 deletions.
4 changes: 2 additions & 2 deletions doc/leaf.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ return leaf::try_catch(
[.text-right]
<<try_catch>> | <<result>>

NOTE: Follow this link to see a complete example program: https://github.com/boostorg/leaf/blob/master/example/try_capture_all_eh.cpp?ts=4[try_capture_all_eh.cpp].
NOTE: Follow this link to see a complete example program: https://github.com/boostorg/leaf/blob/master/example/try_capture_all_exceptions.cpp?ts=4[try_capture_all_exceptions.cpp].

'''

Expand Down Expand Up @@ -1776,7 +1776,7 @@ int main() noexcept

NOTE: Follow this link to see the complete program: https://github.com/boostorg/leaf/blob/master/example/lua_callback_result.cpp?ts=4[lua_callback_result.cpp].

TIP: When using Lua with {CPP}, we need to protect the Lua interpreter from exceptions that may be thrown from {CPP} functions installed as `lua_CFunction` callbacks. Here is the program from this section rewritten to use a {CPP} exception (instead of `leaf::result`) to safely communicate errors out of the `do_work` function: https://github.com/boostorg/leaf/blob/master/example/lua_callback_eh.cpp?ts=4[lua_callback_eh.cpp].
TIP: When using Lua with {CPP}, we need to protect the Lua interpreter from exceptions that may be thrown from {CPP} functions installed as `lua_CFunction` callbacks. Here is the program from this section rewritten to use a {CPP} exception (instead of `leaf::result`) to safely communicate errors out of the `do_work` function: https://github.com/boostorg/leaf/blob/master/example/lua_callback_exceptions.cpp?ts=4[lua_callback_exceptions.cpp].

''''

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/print_file/print_file_leaf_result.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 does not use exception handling. The version that
// does use exception handling is in print_file_eh.cpp.
// does use exception handling is in print_file_exceptions.cpp.

#include <boost/leaf.hpp>

Expand Down
2 changes: 1 addition & 1 deletion example/print_file/print_file_system_result.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 does not use exception handling. The version that
// does use exception handling is in print_file_eh.cpp.
// does use exception handling is in print_file_exceptions.cpp.


#include <boost/leaf.hpp>
Expand Down
2 changes: 1 addition & 1 deletion example/print_file/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ different variation on error handling:
* [print_file_outcome_result.cpp](./print_file_outcome_result.cpp) is the same as
above, but using `boost::outcome::result<T>` instead of `boost::leaf::result<T>`.

* [print_file_eh.cpp](./print_file_eh.cpp) throws on error, using an error code
* [print_file_exceptions.cpp](./print_file_exceptions.cpp) throws on error, using an error code
`enum` for classification of failures.
4 changes: 2 additions & 2 deletions example/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* [print_file](./print_file): The complete example from the [Five Minute Introduction](https://boostorg.github.io/leaf/#introduction). This directory contains several versions of the same program, each using a different error handling style.

* [dynamic_capture_result.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_result.cpp?ts=4): Shows how to transport error objects between threads in a `leaf::result<T>` object without using exception handling.
* [dynamic_capture_eh.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_eh.cpp?ts=4): Shows how to transport error objects between threads in an a `leaf::result<T>` object using exception handling.
* [dynamic_capture_exceptions.cpp](https://github.com/boostorg/leaf/blob/master/example/dynamic_capture_exceptions.cpp?ts=4): Shows how to transport error objects between threads in an a `leaf::result<T>` object using exception handling.
* [lua_callback_result.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_result.cpp?ts=4): Transporting arbitrary error objects through an uncooperative C API.
* [lua_callback_eh.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_eh.cpp?ts=4): Transporting arbitrary error objects through an uncooperative exception-safe API.
* [lua_callback_exceptions.cpp](https://github.com/boostorg/leaf/blob/master/example/lua_callback_exceptions.cpp?ts=4): Transporting arbitrary error objects through an uncooperative exception-safe API.
* [exception_to_result.cpp](https://github.com/boostorg/leaf/blob/master/example/exception_to_result.cpp?ts=4): Demonstrates how to transport exceptions through a `noexcept` layer in the program.
* [exception_error_log.cpp](https://github.com/boostorg/leaf/blob/master/example/error_log.cpp?ts=4): Using `accumulate` to produce an error log.
* [exception_error_trace.cpp](https://github.com/boostorg/leaf/blob/master/example/error_trace.cpp?ts=4): Same as above, but the log is recorded in a `std::deque` rather than just printed.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/try_capture_all_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// This is a simple program that demonstrates the use of LEAF to transport error
// objects between threads, without using exception handling. See capture_eh.cpp
// objects between threads, without using exception handling. See try_capture_all_exceptions.cpp
// for the version that uses exception handling.

#include <boost/leaf/config.hpp>
Expand Down
44 changes: 14 additions & 30 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -238,51 +238,35 @@ endif

if option_enable_examples

print_file_examples = [
'print_file_leaf_result'
]
executable('print_file_leaf_result', 'example/print_file/print_file_leaf_result.cpp', dependencies: [leaf] )
if option_exceptions
print_file_examples += [
'print_file_eh'
]
executable('print_file_exceptions', 'example/print_file/print_file_exceptions.cpp', dependencies: [leaf] )
endif
if option_boost
print_file_examples += [
'print_file_system_result',
'print_file_outcome_result'
]
executable('print_file_system_result', 'example/print_file/print_file_system_result.cpp', dependencies: [leaf, dep_boost] )
executable('print_file_outcome_result', 'example/print_file/print_file_outcome_result.cpp', dependencies: [leaf, dep_boost] )
endif

foreach e : print_file_examples
executable(e, 'example/print_file/'+e+'.cpp', dependencies: [leaf, dep_thread, dep_boost] )
endforeach

endif

#################################

if option_enable_examples

executable('error_log', 'example/error_log.cpp', dependencies: [leaf] )
executable('error_trace', 'example/error_trace.cpp', dependencies: [leaf] )
executable('print_half', 'example/print_half.cpp', dependencies: [leaf] )
executable('try_capture_all_result', 'example/try_capture_all_result.cpp', dependencies: [leaf, dep_thread] )

executable('try_capture_all_result', 'example/try_capture_all_result.cpp', dependencies: [leaf] )
if option_exceptions
executable('try_capture_all_exceptions', 'example/try_capture_all_exceptions.cpp', dependencies: [leaf] )
executable('exception_to_result', 'example/exception_to_result.cpp', dependencies: [leaf] )
executable('try_capture_all_eh', 'example/try_capture_all_eh.cpp', dependencies: [leaf, dep_thread] )
if option_lua
executable('lua_callback_eh', 'example/lua_callback_eh.cpp', dependencies: [leaf, dep_lua] )
endif
if option_boost
executable('asio_beast_leaf_rpc', 'example/asio_beast_leaf_rpc.cpp', dependencies: [leaf, dep_boost], override_options: ['cpp_std=c++17'] )
endif
endif

if option_lua
if option_exceptions
executable('lua_callback_exceptions', 'example/lua_callback_exceptions.cpp', dependencies: [leaf, dep_lua] )
endif
executable('lua_callback_result', 'example/lua_callback_result.cpp', dependencies: [leaf, dep_lua] )
endif

if option_boost and option_exceptions
executable('asio_beast_leaf_rpc', 'example/asio_beast_leaf_rpc.cpp', dependencies: [leaf, dep_boost] )
endif

endif

#################################
Expand All @@ -294,7 +278,7 @@ if option_enable_benchmarks
endif

if option_exceptions
error('The option leaf_enable_benchmarks requires the built-in option cpp_eh set to none. Aborting.')
error('The option leaf_enable_benchmarks requires the built-in option cpp_exceptions set to none. Aborting.')
endif

dep_tl_expected = subproject('tl_expected').get_variable('headers')
Expand Down
15 changes: 8 additions & 7 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ compile-fail _compile-fail-result_2.cpp ;
compile-fail _compile-fail-result_3.cpp ;
compile-fail _compile-fail-result_4.cpp ;

exe try_capture_all_eh : ../example/try_capture_all_eh.cpp : <threading>single:<build>no <exception-handling>off:<build>no <variant>leaf_debug_capture0:<build>no <variant>leaf_release_capture0:<build>no ;
exe try_capture_all_exceptions : ../example/try_capture_all_exceptions.cpp : <threading>single:<build>no <exception-handling>off:<build>no <variant>leaf_debug_capture0:<build>no <variant>leaf_release_capture0:<build>no ;
exe try_capture_all_result : ../example/try_capture_all_result.cpp : <threading>single:<build>no <variant>leaf_debug_capture0:<build>no <variant>leaf_release_capture0:<build>no <variant>leaf_debug_embedded:<build>no <variant>leaf_release_embedded:<build>no ;
exe error_log : ../example/error_log.cpp : <exception-handling>off:<build>no ;
exe error_trace : ../example/error_trace.cpp : <exception-handling>off:<build>no ;
exe error_log : ../example/error_log.cpp ;
exe error_trace : ../example/error_trace.cpp ;
exe exception_to_result : ../example/exception_to_result.cpp : <exception-handling>off:<build>no ;
exe print_file_eh : ../example/print_file/print_file_eh.cpp : <exception-handling>off:<build>no ;
exe print_file_leaf_result : ../example/print_file/print_file_leaf_result.cpp : <exception-handling>off:<build>no ;
exe print_file_system_result : ../example/print_file/print_file_system_result.cpp : <exception-handling>off:<build>no ;
exe print_half : ../example/print_half.cpp : <exception-handling>off:<build>no ;
exe print_file_exceptions : ../example/print_file/print_file_exceptions.cpp : <exception-handling>off:<build>no ;
exe print_file_leaf_result : ../example/print_file/print_file_leaf_result.cpp ;
exe print_file_outcome_result : ../example/print_file/print_file_outcome_result.cpp : <cxxstd>11:<build>no <cxxstd>14:<build>no <variant>leaf_debug_embedded:<build>no <variant>leaf_release_embedded:<build>no ;
exe print_file_system_result : ../example/print_file/print_file_system_result.cpp : <cxxstd>11:<build>no <cxxstd>14:<build>no <variant>leaf_debug_embedded:<build>no <variant>leaf_release_embedded:<build>no ;
exe print_half : ../example/print_half.cpp ;
57 changes: 57 additions & 0 deletions test/result_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -246,6 +249,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -263,6 +269,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -285,6 +294,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -304,6 +316,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -323,6 +338,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -342,6 +360,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -361,6 +382,9 @@ int main()
BOOST_TEST_EQ(err::count, 1);
BOOST_TEST_EQ(val::count, 0);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<val> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand Down Expand Up @@ -414,6 +438,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -430,6 +457,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -447,6 +477,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -465,6 +498,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -484,6 +520,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -502,6 +541,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2 = std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -520,6 +562,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand All @@ -538,6 +583,9 @@ int main()
BOOST_TEST(!r1.operator->());
BOOST_TEST_EQ(err::count, 1);
leaf::error_id r1e = r1.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(std::error_code(r1e) == r1.error());
#endif
leaf::result<void> r2; r2=std::move(r1);
leaf::error_id r2e = r2.error();
BOOST_TEST_EQ(r1e, r2e);
Expand Down Expand Up @@ -572,6 +620,9 @@ int main()
BOOST_TEST_EQ(val::count, 0);
BOOST_TEST(!r1);
leaf::error_id id = r.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(!std::error_code(r.error()));
#endif
BOOST_TEST(!id);
}
BOOST_TEST_EQ(val::count, 0);
Expand All @@ -582,6 +633,9 @@ int main()
leaf::result<void> r1 = r.error();
BOOST_TEST(!r1);
leaf::error_id id = r.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(!std::error_code(r.error()));
#endif
BOOST_TEST(!id);
BOOST_TEST_EQ(val::count, 1);
}
Expand All @@ -593,6 +647,9 @@ int main()
leaf::result<float> r1 = r.error();
BOOST_TEST(!r1);
leaf::error_id id = r.error();
#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR
BOOST_TEST(!std::error_code(r.error()));
#endif
BOOST_TEST(!id);
BOOST_TEST_EQ(val::count, 1);
}
Expand Down

0 comments on commit 72578fa

Please sign in to comment.