Added support for completely disabling noexcept using MIJIN_TEST_NO_NOEXCEPT (for testing).
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "../debug/assert.hpp"
|
||||
#include "../internal/common.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
@@ -27,7 +28,7 @@ public:
|
||||
using get_t = TGet;
|
||||
using set_t = TSet;
|
||||
|
||||
virtual ~PropertyStorage() noexcept = default;
|
||||
virtual ~PropertyStorage() MIJIN_NOEXCEPT = default;
|
||||
|
||||
[[nodiscard]] virtual TGet getValue() = 0;
|
||||
virtual void setValue(TSet value) = 0;
|
||||
@@ -39,15 +40,15 @@ class SimplePropertyStorage : public PropertyStorage<T>
|
||||
private:
|
||||
T value_;
|
||||
public:
|
||||
SimplePropertyStorage() noexcept = default;
|
||||
SimplePropertyStorage(const SimplePropertyStorage& other) noexcept(noexcept(T(other.value_))) = default;
|
||||
SimplePropertyStorage(SimplePropertyStorage&& other) noexcept(noexcept(T(std::move(other.value_)))) = default;
|
||||
explicit SimplePropertyStorage(T value) noexcept(noexcept(T(std::move(value)))) : value_(std::move(value)) {}
|
||||
SimplePropertyStorage() MIJIN_NOEXCEPT = default;
|
||||
SimplePropertyStorage(const SimplePropertyStorage& other) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(T(other.value_))) = default;
|
||||
SimplePropertyStorage(SimplePropertyStorage&& other) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(T(std::move(other.value_)))) = default;
|
||||
explicit SimplePropertyStorage(T value) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(T(std::move(value)))) : value_(std::move(value)) {}
|
||||
|
||||
SimplePropertyStorage& operator=(const SimplePropertyStorage& other) noexcept(noexcept(value_ = other.value_)) = default;
|
||||
SimplePropertyStorage& operator=(SimplePropertyStorage&& other) noexcept(noexcept(value_ = std::move(other.value_))) = default;
|
||||
SimplePropertyStorage& operator=(const SimplePropertyStorage& other) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(value_ = other.value_)) = default;
|
||||
SimplePropertyStorage& operator=(SimplePropertyStorage&& other) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(value_ = std::move(other.value_))) = default;
|
||||
|
||||
const T& getValue() noexcept override { return value_; }
|
||||
const T& getValue() MIJIN_NOEXCEPT override { return value_; }
|
||||
void setValue(T value) override { value_ = std::move(value); }
|
||||
};
|
||||
|
||||
@@ -65,30 +66,30 @@ public:
|
||||
private:
|
||||
Property* base_;
|
||||
public:
|
||||
explicit PropertyProxy(Property* base) noexcept : base_(base) {}
|
||||
explicit PropertyProxy(Property* base) MIJIN_NOEXCEPT : base_(base) {}
|
||||
|
||||
operator TGet() noexcept { return base_->get(); }
|
||||
PropertyProxy& operator=(TSet value) noexcept(noexcept(std::declval<T&>() = std::move(value)))
|
||||
operator TGet() MIJIN_NOEXCEPT { return base_->get(); }
|
||||
PropertyProxy& operator=(TSet value) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(std::declval<T&>() = std::move(value)))
|
||||
{
|
||||
base_->set(std::move(value));
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
Property() noexcept = default;
|
||||
explicit Property(storage_ptr_t storage) noexcept : storage_(std::move(storage)) {}
|
||||
Property(Property&&) noexcept = default;
|
||||
Property() MIJIN_NOEXCEPT = default;
|
||||
explicit Property(storage_ptr_t storage) MIJIN_NOEXCEPT : storage_(std::move(storage)) {}
|
||||
Property(Property&&) MIJIN_NOEXCEPT = default;
|
||||
|
||||
Property& operator=(Property&&) noexcept = default;
|
||||
PropertyProxy operator*() noexcept { return PropertyProxy(this); }
|
||||
std::remove_reference_t<TGet>* operator->() const noexcept { return &get(); }
|
||||
Property& operator=(Property&&) MIJIN_NOEXCEPT = default;
|
||||
PropertyProxy operator*() MIJIN_NOEXCEPT { return PropertyProxy(this); }
|
||||
std::remove_reference_t<TGet>* operator->() const MIJIN_NOEXCEPT { return &get(); }
|
||||
|
||||
[[nodiscard]] TGet get() const noexcept
|
||||
[[nodiscard]] TGet get() const MIJIN_NOEXCEPT
|
||||
{
|
||||
MIJIN_ASSERT_FATAL(storage_ != nullptr, "Cannot get value from an unset property.");
|
||||
return storage_->getValue();
|
||||
}
|
||||
void set(TSet value) noexcept(noexcept(std::declval<T&>() = std::move(value)))
|
||||
void set(TSet value) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(std::declval<T&>() = std::move(value)))
|
||||
{
|
||||
MIJIN_ASSERT_FATAL(storage_ != nullptr, "Cannot set value of an unset property.");
|
||||
storage_->setValue(std::move<TSet>(value));
|
||||
@@ -99,7 +100,7 @@ template<typename TStorage>
|
||||
Property(std::unique_ptr<TStorage>) -> Property<typename TStorage::value_t, typename TStorage::get_t, typename TStorage::set_t>;
|
||||
|
||||
template<typename T>
|
||||
Property<T> makeSimpleProperty(T value) noexcept(noexcept(std::declval<T&>() = std::move(value)))
|
||||
Property<T> makeSimpleProperty(T value) MIJIN_CONDITIONAL_NOEXCEPT(noexcept(std::declval<T&>() = std::move(value)))
|
||||
{
|
||||
return Property(std::make_unique<SimplePropertyStorage<T>>(std::move(value)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user