rsl  1.1.0
ROS Support Library
try.hpp File Reference
#include <tl_expected/expected.hpp>

Go to the source code of this file.

Macros

#define TRY(expected)
 Unwrap an expected into a stack variable or return the unexpected value. More...
 

Macro Definition Documentation

◆ TRY

#define TRY (   expected)
Value:
({ \
auto const& _expected = (expected); /* Uglify name to prevent shadowing */ \
if (!_expected.has_value()) return tl::unexpected(_expected.error()); \
_expected.value(); \
})

Unwrap an expected into a stack variable or return the unexpected value.

This macro requires the use of non-standard C++. Compiler extensions must be enabled and -Wpedantic cannot be used. With GCC and Clang, you can disable -Wpedantic for an entire translation unit like this:

#pragma GCC diagnostic ignored "-Wpedantic"

You can disable -Wpedantic for a specific segment of code like so:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
//...
#pragma GCC diagnostic pop

For more information on this particular compiler extension go to https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html