62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#if defined(__has_include)
|
|
#if __has_include(<expected>) && defined(__cpp_lib_expected) && (__cpp_lib_expected >= 202202L)
|
|
#include <expected>
|
|
#define HAS_STD_EXPECTED 1
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(HAS_STD_EXPECTED)
|
|
|
|
namespace Psc {
|
|
template<class T, class E>
|
|
using expected = std::expected<T, E>;
|
|
|
|
template<class E>
|
|
using unexpected = std::unexpected<E>;
|
|
|
|
template<class E>
|
|
using bad_expected_access = std::bad_expected_access<E>;
|
|
|
|
using unexpect_t = std::unexpect_t;
|
|
inline constexpr unexpect_t unexpect = std::unexpect;
|
|
}
|
|
|
|
#else
|
|
|
|
#include "../3rd/tl/expected.hpp"
|
|
|
|
namespace Psc {
|
|
template<class T, class E>
|
|
using expected = tl::expected<T, E>;
|
|
|
|
template<class E>
|
|
using unexpected = tl::unexpected<E>;
|
|
|
|
template<class E>
|
|
using bad_expected_access = tl::bad_expected_access<E>;
|
|
|
|
// tl 版本通常也有 unexpect_t / unexpect(名字可能略不同,按你的 tl/expected.hpp 实际为准)
|
|
using unexpect_t = tl::unexpect_t;
|
|
inline constexpr unexpect_t unexpect{};
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
#include <system_error>
|
|
#include <cstdint>
|
|
|
|
namespace Psc {
|
|
#ifdef WIN32
|
|
using ERROR_CODE_TYPE = int;
|
|
#else
|
|
using ERROR_CODE_TYPE = int;
|
|
#endif
|
|
ERROR_CODE_TYPE get_error_code();
|
|
void set_error_code(ERROR_CODE_TYPE code);
|
|
std::string get_error_message();
|
|
std::string get_error_message(ERROR_CODE_TYPE ec);
|
|
}
|