Add error

This commit is contained in:
mutouyun 2025-01-07 20:09:09 +08:00 committed by 木头云
parent e7b6fcd79d
commit 4c1f829c06
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/**
* \file libipc/error.h
* \author mutouyun (orz@orzz.org)
* \brief A platform-dependent error code.
*/
#pragma once
#include <system_error>
#include <string>
#include <cstdint>
#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

View File

@ -0,0 +1,12 @@
#include <iostream>
#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');
}