mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Add error
This commit is contained in:
parent
e7b6fcd79d
commit
4c1f829c06
27
include/libipc/imp/error.h
Normal file
27
include/libipc/imp/error.h
Normal 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
|
||||||
12
test/imp/test_imp_error.cpp
Normal file
12
test/imp/test_imp_error.cpp
Normal 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');
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user