用的c++20。只能先这么污染一下std,这样以后不用改代码。
#pragma once
#if defined(__cpp_lib_expected) && (__cpp_lib_expected >= 202211L)
#include <expected>
#else
#include <tl/expected.hpp>
#include <type_traits>
#include <utility>
namespace std {
template <typename T, typename E> using expected = tl::expected<T, E>;
template <typename E> using unexpected = tl::unexpected<E>;
template <typename E> auto make_unexpected(E &&e) -> unexpected<std::remove_cvref_t<E>> {
return unexpected<std::remove_cvref_t<E>>(std::forward<E>(e));
}
} // namespace std
#endif
--
FROM 111.199.147.*