diff --git a/include/libipc/imp/error.h b/include/libipc/imp/error.h new file mode 100644 index 0000000..6493b0b --- /dev/null +++ b/include/libipc/imp/error.h @@ -0,0 +1,27 @@ +/** + * \file libipc/error.h + * \author mutouyun (orz@orzz.org) + * \brief A platform-dependent error code. + */ +#pragma once + +#include +#include +#include + +#include "libipc/imp/export.h" +#include "libipc/imp/fmt_cpo.h" + +namespace ipc { + +/** + * \brief Custom defined fmt_to method for imp::fmt + */ +namespace detail_tag_invoke { + +inline bool tag_invoke(decltype(ipc::fmt_to), fmt_context &ctx, std::error_code const &ec) noexcept { + return fmt_to(ctx, '[', ec.value(), ": ", ec.message(), ']'); +} + +} // namespace detail_tag_invoke +} // namespace ipc diff --git a/test/imp/test_imp_error.cpp b/test/imp/test_imp_error.cpp new file mode 100644 index 0000000..b8db0e6 --- /dev/null +++ b/test/imp/test_imp_error.cpp @@ -0,0 +1,12 @@ +#include + +#include "test.h" + +#include "libipc/imp/error.h" +#include "libipc/imp/fmt.h" + +TEST(error, error_code) { + std::error_code ecode; + EXPECT_FALSE(ecode); + std::cout << ipc::fmt(ecode, '\n'); +}