Added support for completely disabling noexcept using MIJIN_TEST_NO_NOEXCEPT (for testing).

This commit is contained in:
2024-08-29 00:01:23 +02:00
parent a43f92fb58
commit 9ba097fc2f
41 changed files with 643 additions and 564 deletions

View File

@@ -7,6 +7,7 @@
#include <variant>
#include "../async/coroutine.hpp"
#include "../container/optional.hpp"
#include "../internal/common.hpp"
#include "../io/stream.hpp" // TODO: rename Stream{Error,Result} to IO{*}
namespace mijin
@@ -15,29 +16,29 @@ struct IPv4Address
{
std::array<std::uint8_t, 4> octets;
auto operator<=>(const IPv4Address&) const noexcept = default;
auto operator<=>(const IPv4Address&) const MIJIN_NOEXCEPT = default;
[[nodiscard]] std::string toString() const;
[[nodiscard]]
static Optional<IPv4Address> fromString(std::string_view stringView) noexcept;
static Optional<IPv4Address> fromString(std::string_view stringView) MIJIN_NOEXCEPT;
};
struct IPv6Address
{
std::array<std::uint16_t, 8> hextets;
auto operator<=>(const IPv6Address&) const noexcept = default;
auto operator<=>(const IPv6Address&) const MIJIN_NOEXCEPT = default;
[[nodiscard]] std::string toString() const;
[[nodiscard]]
static Optional<IPv6Address> fromString(std::string_view stringView) noexcept;
static Optional<IPv6Address> fromString(std::string_view stringView) MIJIN_NOEXCEPT;
};
using ip_address_t = std::variant<IPv4Address, IPv6Address>;
[[nodiscard]]
inline std::string ipAddressToString(const ip_address_t& address) noexcept
inline std::string ipAddressToString(const ip_address_t& address) MIJIN_NOEXCEPT
{
if (address.valueless_by_exception())
{
@@ -47,7 +48,7 @@ inline std::string ipAddressToString(const ip_address_t& address) noexcept
}
[[nodiscard]]
inline Optional<ip_address_t> ipAddressFromString(std::string_view stringView) noexcept
inline Optional<ip_address_t> ipAddressFromString(std::string_view stringView) MIJIN_NOEXCEPT
{
if (Optional<IPv4Address> ipv4Address = IPv4Address::fromString(stringView); !ipv4Address.empty())
{
@@ -61,16 +62,16 @@ inline Optional<ip_address_t> ipAddressFromString(std::string_view stringView) n
}
[[nodiscard]]
Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(std::string hostname) noexcept;
Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(std::string hostname) MIJIN_NOEXCEPT;
[[nodiscard]]
inline Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(std::string_view hostname) noexcept
inline Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(std::string_view hostname) MIJIN_NOEXCEPT
{
return c_resolveHostname(std::string(hostname.begin(), hostname.end()));
}
[[nodiscard]]
inline Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(const char* hostname) noexcept
inline Task<StreamResult<std::vector<ip_address_t>>> c_resolveHostname(const char* hostname) MIJIN_NOEXCEPT
{
return c_resolveHostname(std::string(hostname));
}