Added support for completely disabling noexcept using MIJIN_TEST_NO_NOEXCEPT (for testing).
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#if __has_include(<fmt/format.h>)
|
||||
# include <fmt/format.h>
|
||||
#endif
|
||||
#include "../internal/common.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
@@ -37,8 +38,8 @@ public:
|
||||
|
||||
Name& operator=(const Name&) = default;
|
||||
auto operator<=>(const Name&) const = default;
|
||||
constexpr operator bool() const noexcept { return id_ != std::numeric_limits<std::size_t>::max(); }
|
||||
constexpr bool operator!() const noexcept { return !static_cast<bool>(*this); }
|
||||
constexpr operator bool() const MIJIN_NOEXCEPT { return id_ != std::numeric_limits<std::size_t>::max(); }
|
||||
constexpr bool operator!() const MIJIN_NOEXCEPT { return !static_cast<bool>(*this); }
|
||||
|
||||
[[nodiscard]] std::string_view stringView() const;
|
||||
[[nodiscard]] const char* c_str() const {
|
||||
@@ -57,7 +58,7 @@ public:
|
||||
template<>
|
||||
struct std::hash<mijin::Name> : hash<std::size_t>
|
||||
{
|
||||
std::size_t operator()(mijin::Name name) const noexcept {
|
||||
std::size_t operator()(mijin::Name name) const MIJIN_NOEXCEPT {
|
||||
return hash<std::size_t>::operator()(name.getID());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "../internal/common.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
@@ -30,32 +32,32 @@ private:
|
||||
|
||||
std::variant<Empty, TSuccess, TError> state_;
|
||||
public:
|
||||
ResultBase() = default;
|
||||
ResultBase(const ResultBase&) = default;
|
||||
ResultBase(ResultBase&&) = default;
|
||||
ResultBase(TSuccess successValue) noexcept : state_(std::move(successValue)) {}
|
||||
ResultBase(TError errorValue) noexcept : state_(std::move(errorValue)) {}
|
||||
ResultBase() MIJIN_NOEXCEPT = default;
|
||||
ResultBase(const ResultBase&) MIJIN_NOEXCEPT = default;
|
||||
ResultBase(ResultBase&&) MIJIN_NOEXCEPT = default;
|
||||
ResultBase(TSuccess successValue) MIJIN_NOEXCEPT : state_(std::move(successValue)) {}
|
||||
ResultBase(TError errorValue) MIJIN_NOEXCEPT : state_(std::move(errorValue)) {}
|
||||
|
||||
ResultBase& operator=(const ResultBase&) = default;
|
||||
ResultBase& operator=(ResultBase&&) = default;
|
||||
|
||||
bool operator==(const ResultBase& other) const noexcept { return state_ == other.state_; }
|
||||
bool operator!=(const ResultBase& other) const noexcept { return state_ != other.state_; }
|
||||
operator bool() const noexcept { return isSuccess(); }
|
||||
bool operator!() const noexcept { return !isSuccess(); }
|
||||
TSuccess& operator*() noexcept { return getValue(); }
|
||||
const TSuccess& operator*() const noexcept { return getValue(); }
|
||||
TSuccess* operator->() noexcept { return &getValue(); }
|
||||
const TSuccess* operator->() const noexcept { return &getValue(); }
|
||||
bool operator==(const ResultBase& other) const MIJIN_NOEXCEPT { return state_ == other.state_; }
|
||||
bool operator!=(const ResultBase& other) const MIJIN_NOEXCEPT { return state_ != other.state_; }
|
||||
operator bool() const MIJIN_NOEXCEPT { return isSuccess(); }
|
||||
bool operator!() const MIJIN_NOEXCEPT { return !isSuccess(); }
|
||||
TSuccess& operator*() MIJIN_NOEXCEPT { return getValue(); }
|
||||
const TSuccess& operator*() const MIJIN_NOEXCEPT { return getValue(); }
|
||||
TSuccess* operator->() MIJIN_NOEXCEPT { return &getValue(); }
|
||||
const TSuccess* operator->() const MIJIN_NOEXCEPT { return &getValue(); }
|
||||
|
||||
[[nodiscard]] bool isEmpty() const noexcept { return std::holds_alternative<Empty>(state_); }
|
||||
[[nodiscard]] bool isSuccess() const noexcept { return std::holds_alternative<TSuccess>(state_); }
|
||||
[[nodiscard]] bool isError() const noexcept { return std::holds_alternative<TError>(state_); }
|
||||
[[nodiscard]] bool isEmpty() const MIJIN_NOEXCEPT { return std::holds_alternative<Empty>(state_); }
|
||||
[[nodiscard]] bool isSuccess() const MIJIN_NOEXCEPT { return std::holds_alternative<TSuccess>(state_); }
|
||||
[[nodiscard]] bool isError() const MIJIN_NOEXCEPT { return std::holds_alternative<TError>(state_); }
|
||||
|
||||
[[nodiscard]] TSuccess& getValue() noexcept { return std::get<TSuccess>(state_); }
|
||||
[[nodiscard]] TError& getError() noexcept { return std::get<TError>(state_); }
|
||||
[[nodiscard]] const TSuccess& getValue() const noexcept { return std::get<TSuccess>(state_); }
|
||||
[[nodiscard]] const TError& getError() const noexcept { return std::get<TError>(state_); }
|
||||
[[nodiscard]] TSuccess& getValue() MIJIN_NOEXCEPT { return std::get<TSuccess>(state_); }
|
||||
[[nodiscard]] TError& getError() MIJIN_NOEXCEPT { return std::get<TError>(state_); }
|
||||
[[nodiscard]] const TSuccess& getValue() const MIJIN_NOEXCEPT { return std::get<TSuccess>(state_); }
|
||||
[[nodiscard]] const TError& getError() const MIJIN_NOEXCEPT { return std::get<TError>(state_); }
|
||||
};
|
||||
|
||||
struct ResultError
|
||||
@@ -64,11 +66,11 @@ struct ResultError
|
||||
|
||||
ResultError() : message("Unknown error") {}
|
||||
ResultError(const ResultError&) = default;
|
||||
ResultError(ResultError&&) noexcept = default;
|
||||
ResultError(std::string msg) noexcept : message(std::move(msg)) {}
|
||||
ResultError(ResultError&&) MIJIN_NOEXCEPT = default;
|
||||
ResultError(std::string msg) MIJIN_NOEXCEPT : message(std::move(msg)) {}
|
||||
|
||||
ResultError& operator=(const ResultError&) = default;
|
||||
ResultError& operator=(ResultError&&) noexcept = default;
|
||||
ResultError& operator=(ResultError&&) MIJIN_NOEXCEPT = default;
|
||||
};
|
||||
|
||||
template<typename TSuccess>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "../container/optional.hpp"
|
||||
#include "../internal/common.hpp"
|
||||
#include "../util/traits.hpp"
|
||||
#include "../util/variant.hpp"
|
||||
|
||||
@@ -73,14 +74,14 @@ public:
|
||||
private:
|
||||
base_t base_ = UndefinedValue();
|
||||
public:
|
||||
ScriptValue() noexcept = default;
|
||||
ScriptValue(const ScriptValue&) noexcept = default;
|
||||
ScriptValue(ScriptValue&&) noexcept = default;
|
||||
ScriptValue() MIJIN_NOEXCEPT = default;
|
||||
ScriptValue(const ScriptValue&) MIJIN_NOEXCEPT = default;
|
||||
ScriptValue(ScriptValue&&) MIJIN_NOEXCEPT = default;
|
||||
template<typename TValue>
|
||||
ScriptValue(TValue&& value);
|
||||
|
||||
ScriptValue& operator=(const ScriptValue&) = default;
|
||||
ScriptValue& operator=(ScriptValue&&) noexcept = default;
|
||||
ScriptValue& operator=(ScriptValue&&) MIJIN_NOEXCEPT = default;
|
||||
|
||||
std::partial_ordering operator<=>(const ScriptValue& other) const = default;
|
||||
|
||||
@@ -91,7 +92,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Optional<script_int_t> toInt() const noexcept
|
||||
Optional<script_int_t> toInt() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return visit([&](auto&& value) -> Optional<script_int_t>
|
||||
{
|
||||
@@ -118,7 +119,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Optional<script_float_t> toFloat() const noexcept
|
||||
Optional<script_float_t> toFloat() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return visit([&](auto&& value) -> Optional<script_float_t>
|
||||
{
|
||||
@@ -145,7 +146,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Optional<std::string> toString() const noexcept
|
||||
Optional<std::string> toString() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return visit([](auto&& value) -> Optional<std::string>
|
||||
{
|
||||
@@ -175,7 +176,7 @@ public:
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
Optional<std::decay_t<T>> to() const noexcept
|
||||
Optional<std::decay_t<T>> to() const MIJIN_NOEXCEPT
|
||||
{
|
||||
using type_t = std::decay_t<T>;
|
||||
if constexpr (std::is_same_v<type_t, script_int_t>)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#define MIJIN_TYPES_TYPEDEF_HPP_INCLUDED 1
|
||||
|
||||
#include <utility>
|
||||
#include "../internal/common.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
@@ -48,9 +49,9 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit constexpr operator const TBase&() const noexcept { return value; }
|
||||
explicit constexpr operator TBase&() noexcept { return value; }
|
||||
auto operator<=>(const TypeDef&) const noexcept = default;
|
||||
explicit constexpr operator const TBase&() const MIJIN_NOEXCEPT { return value; }
|
||||
explicit constexpr operator TBase&() MIJIN_NOEXCEPT { return value; }
|
||||
auto operator<=>(const TypeDef&) const MIJIN_NOEXCEPT = default;
|
||||
};
|
||||
|
||||
template<typename TBase, typename TTag> requires (!std::is_fundamental_v<TBase>)
|
||||
|
||||
Reference in New Issue
Block a user