ADL 桥接
注意
在上一节中,我们使用了 failure_info 类型来创建 ADL 桥接,连接到 ADL 能够发现 outcome_throw_as_system_error_with_payload() 函数的命名空间。
在这里,我们做同样的事情,但更直接,通过在本地命名空间创建一个 std::error_code 的薄克隆。这确保了在发现事件钩子时(仅限 Outcome v2.1 及更早版本),编译器会搜索此命名空间。
namespace error_code_extended
{
// Use the error_code type as the ADL bridge for the hooks by creating a type here
// It can be any type that your localised result uses, including the value type but
// by localising the error code type here you prevent nasty surprises later when the
// value type you use doesn't trigger the ADL bridge.
struct error_code : public std::error_code
{
// literally passthrough
using std::error_code::error_code;
error_code() = default;
error_code(std::error_code ec)
: std::error_code(ec)
{
}
};
// Localise result and outcome to using the local error_code so this namespace gets looked up for the hooks
template <class R> using result = BOOST_OUTCOME_V2_NAMESPACE::result<R, error_code>;
template <class R> using outcome = BOOST_OUTCOME_V2_NAMESPACE::outcome<R, error_code /*, std::exception_ptr */>;
}
为了方便起见,我们在与 ADL 桥接 error_code 绑定的此命名空间中,将 result 和 outcome 的本地副本模板化为别名。



