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

@@ -4,10 +4,12 @@
#if !defined(MIJIN_UTIL_ALIGN_HPP_INCLUDED)
#define MIJIN_UTIL_ALIGN_HPP_INCLUDED 1
#include "../internal/common.hpp"
namespace mijin
{
template<typename T>
constexpr T alignUp(T value, T alignTo) noexcept
constexpr T alignUp(T value, T alignTo) MIJIN_NOEXCEPT
{
if (value % alignTo != 0)
{

View File

@@ -7,6 +7,7 @@
#include <cstdint>
#include "./traits.hpp"
#include "./types.hpp"
#include "../internal/common.hpp"
namespace mijin
{
@@ -15,23 +16,23 @@ namespace mijin
// public defines
//
#define MIJIN_DEFINE_FLAG(name) \
struct name : mijin::Flag \
{ \
private: \
struct Proxy_ { \
uint8_t value; \
}; \
public: \
constexpr name() = default; \
constexpr name(const name&) = default; \
constexpr name(Proxy_ proxy) \
: Flag(proxy.value) {} \
constexpr explicit name(bool value) noexcept \
: Flag(value) {} \
name& operator=(const name&) = default; \
static constexpr Proxy_ YES{1}; \
static constexpr Proxy_ NO{0}; \
#define MIJIN_DEFINE_FLAG(name) \
struct name : mijin::Flag \
{ \
private: \
struct Proxy_ { \
uint8_t value; \
}; \
public: \
constexpr name() = default; \
constexpr name(const name&) = default; \
constexpr name(Proxy_ proxy) MIJIN_NOEXCEPT \
: Flag(proxy.value) {} \
constexpr explicit name(bool value) MIJIN_NOEXCEPT \
: Flag(value) {} \
name& operator=(const name&) = default; \
static constexpr Proxy_ YES{1}; \
static constexpr Proxy_ NO{0}; \
}
//
@@ -48,23 +49,23 @@ struct Flag
Flag() = default;
Flag(const Flag&) = default;
explicit constexpr Flag(uint8_t value) noexcept : value(value) {}
explicit constexpr Flag(uint8_t value) MIJIN_NOEXCEPT : value(value) {}
Flag& operator=(const Flag&) = default;
constexpr bool operator ==(const Flag& other) const noexcept
constexpr bool operator ==(const Flag& other) const MIJIN_NOEXCEPT
{
return value == other.value;
}
constexpr bool operator !=(const Flag& other) const noexcept
constexpr bool operator !=(const Flag& other) const MIJIN_NOEXCEPT
{
return value != other.value;
}
constexpr bool operator !() const noexcept
constexpr bool operator !() const MIJIN_NOEXCEPT
{
return !value;
}
constexpr operator bool() const noexcept
constexpr operator bool() const MIJIN_NOEXCEPT
{
return value != 0;
}
@@ -89,7 +90,7 @@ private:
using base_t = FlagSetStorage<offset + 1, TMore...>;
static constexpr typename base_t::data_t BIT = (1 << offset);
public:
constexpr void set(TFirst value) noexcept
constexpr void set(TFirst value) MIJIN_NOEXCEPT
{
if (value)
{
@@ -100,7 +101,7 @@ public:
base_t::data_ &= ~BIT;
}
}
constexpr bool get(TFirst) noexcept
constexpr bool get(TFirst) MIJIN_NOEXCEPT
{
return (base_t::data_ & BIT) != 0;
}
@@ -134,19 +135,19 @@ public:
public:
FlagSet& operator=(const FlagSet&) = default;
template<FlagType T> requires is_any_type_v<T, TFlags...>
FlagSet& operator=(T flag) noexcept
FlagSet& operator=(T flag) MIJIN_NOEXCEPT
{
reset(flag);
return *this;
}
template<FlagType T> requires is_any_type_v<T, TFlags...>
FlagSet& operator|=(T flag) noexcept
FlagSet& operator|=(T flag) MIJIN_NOEXCEPT
{
set(flag);
return *this;
}
template<FlagType T> requires is_any_type_v<T, TFlags...>
FlagSet& operator&=(T flag) noexcept
FlagSet& operator&=(T flag) MIJIN_NOEXCEPT
{
unset(flag);
}

View File

@@ -11,6 +11,7 @@
#include <tuple>
#include <variant>
#include "../container/optional.hpp"
#include "../internal/common.hpp"
namespace mijin
{
@@ -96,50 +97,50 @@ struct EnumeratingIterator
TIdx idx;
TIterator base;
EnumeratingIterator(TIdx idx_, TIterator base_) noexcept : idx(idx_), base(base_) {}
EnumeratingIterator(const EnumeratingIterator&) noexcept = default;
EnumeratingIterator(TIdx idx_, TIterator base_) MIJIN_NOEXCEPT : idx(idx_), base(base_) {}
EnumeratingIterator(const EnumeratingIterator&) MIJIN_NOEXCEPT = default;
EnumeratingIterator& operator=(const EnumeratingIterator&) noexcept = default;
EnumeratingIterator& operator=(const EnumeratingIterator&) MIJIN_NOEXCEPT = default;
auto operator*() const noexcept
auto operator*() const MIJIN_NOEXCEPT
{
return std::tie(idx, *base);
}
EnumeratingIterator& operator++() noexcept
EnumeratingIterator& operator++() MIJIN_NOEXCEPT
{
++idx;
++base;
return *this;
}
EnumeratingIterator operator++(int) noexcept
EnumeratingIterator operator++(int) MIJIN_NOEXCEPT
{
EnumeratingIterator copy(*this);
++(*this);
return copy;
}
EnumeratingIterator& operator--() noexcept
EnumeratingIterator& operator--() MIJIN_NOEXCEPT
{
--idx;
--base;
return *this;
}
EnumeratingIterator operator--(int) noexcept
EnumeratingIterator operator--(int) MIJIN_NOEXCEPT
{
EnumeratingIterator copy(*this);
--(*this);
return copy;
}
bool operator==(const EnumeratingIterator& other) const noexcept
bool operator==(const EnumeratingIterator& other) const MIJIN_NOEXCEPT
{
return base == other.base; // note: ignoring idx so we don't have to find it out for end()
}
bool operator!=(const EnumeratingIterator& other) const noexcept
bool operator!=(const EnumeratingIterator& other) const MIJIN_NOEXCEPT
{
return base != other.base; // note: ignoring idx so we don't have to find it out for end()
}
@@ -152,12 +153,12 @@ struct Enumeratable : RangeAdapter
{
RangeRef<TIterable> base;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return EnumeratingIterator(TIdx(0), base.begin());
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return EnumeratingIterator(TIdx(0), base.end());
}
@@ -175,50 +176,50 @@ struct ZippingIterator
TFirstIterator first;
TSecondIterator second;
ZippingIterator(TFirstIterator first_, TSecondIterator second_) noexcept : first(first_), second(second_) {}
ZippingIterator(const ZippingIterator&) noexcept = default;
ZippingIterator(TFirstIterator first_, TSecondIterator second_) MIJIN_NOEXCEPT : first(first_), second(second_) {}
ZippingIterator(const ZippingIterator&) MIJIN_NOEXCEPT = default;
ZippingIterator& operator=(const ZippingIterator&) noexcept = default;
ZippingIterator& operator=(const ZippingIterator&) MIJIN_NOEXCEPT = default;
decltype(auto) operator*() const noexcept
decltype(auto) operator*() const MIJIN_NOEXCEPT
{
return std::tie(*first, *second);
}
ZippingIterator& operator++() noexcept
ZippingIterator& operator++() MIJIN_NOEXCEPT
{
++first;
++second;
return *this;
}
ZippingIterator operator++(int) noexcept
ZippingIterator operator++(int) MIJIN_NOEXCEPT
{
ZippingIterator copy(*this);
++(*this);
return copy;
}
ZippingIterator& operator--() noexcept
ZippingIterator& operator--() MIJIN_NOEXCEPT
{
--first;
--second;
return *this;
}
ZippingIterator operator--(int) noexcept
ZippingIterator operator--(int) MIJIN_NOEXCEPT
{
ZippingIterator copy(*this);
--(*this);
return copy;
}
bool operator==(const ZippingIterator& other) const noexcept
bool operator==(const ZippingIterator& other) const MIJIN_NOEXCEPT
{
return first == other.first || second == other.second; // note: this uses or so reaching the end on one range also ends the zipped one.
}
bool operator!=(const ZippingIterator& other) const noexcept
bool operator!=(const ZippingIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -232,12 +233,12 @@ struct ZippingRange : RangeAdapter
RangeRef<TFirst> first;
RangeRef<TSecond> second;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return ZippingIterator(first.begin(), second.begin());
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return ZippingIterator(first.end(), second.end());
}
@@ -262,12 +263,12 @@ struct ReplacingIterator
value_type what;
value_type with;
ReplacingIterator(TIterator base_, value_type what_, value_type with_) noexcept : base(base_), what(what_), with(with_) {}
ReplacingIterator(const ReplacingIterator&) noexcept = default;
ReplacingIterator(TIterator base_, value_type what_, value_type with_) MIJIN_NOEXCEPT : base(base_), what(what_), with(with_) {}
ReplacingIterator(const ReplacingIterator&) MIJIN_NOEXCEPT = default;
ReplacingIterator& operator=(const ReplacingIterator&) noexcept = default;
ReplacingIterator& operator=(const ReplacingIterator&) MIJIN_NOEXCEPT = default;
pointer operator->() const noexcept
pointer operator->() const MIJIN_NOEXCEPT
{
if (*base == what) {
return &with;
@@ -275,7 +276,7 @@ struct ReplacingIterator
return &*base;
}
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
if (*base == what) {
return with;
@@ -283,38 +284,38 @@ struct ReplacingIterator
return *base;
}
ReplacingIterator& operator++() noexcept
ReplacingIterator& operator++() MIJIN_NOEXCEPT
{
++base;
return *this;
}
ReplacingIterator operator++(int) noexcept
ReplacingIterator operator++(int) MIJIN_NOEXCEPT
{
ReplacingIterator copy(*this);
++(*this);
return copy;
}
ReplacingIterator& operator--() noexcept
ReplacingIterator& operator--() MIJIN_NOEXCEPT
{
--base;
return *this;
}
ReplacingIterator operator--(int) noexcept
ReplacingIterator operator--(int) MIJIN_NOEXCEPT
{
ReplacingIterator copy(*this);
--(*this);
return copy;
}
bool operator==(const ReplacingIterator& other) const noexcept
bool operator==(const ReplacingIterator& other) const MIJIN_NOEXCEPT
{
return what == other.what && with == other.with && base == other.base;
}
bool operator!=(const ReplacingIterator& other) const noexcept
bool operator!=(const ReplacingIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -329,12 +330,12 @@ struct ReplacingRange : RangeAdapter
value_type what;
value_type with;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return ReplacingIterator(base.begin(), what, with);
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return ReplacingIterator(base.end(), what, with);
}
@@ -368,14 +369,14 @@ struct MappingIterator
TFunctor functor;
mutable Optional<value_type> result;
MappingIterator(TIterator base_, TFunctor functor_) noexcept : base(base_), functor(std::move(functor_)) {}
MappingIterator(const MappingIterator&) noexcept = default;
MappingIterator(MappingIterator&&) noexcept = default;
MappingIterator(TIterator base_, TFunctor functor_) MIJIN_NOEXCEPT : base(base_), functor(std::move(functor_)) {}
MappingIterator(const MappingIterator&) MIJIN_NOEXCEPT = default;
MappingIterator(MappingIterator&&) MIJIN_NOEXCEPT = default;
MappingIterator& operator=(const MappingIterator&) noexcept = default;
MappingIterator& operator=(MappingIterator&&) noexcept = default;
MappingIterator& operator=(const MappingIterator&) MIJIN_NOEXCEPT = default;
MappingIterator& operator=(MappingIterator&&) MIJIN_NOEXCEPT = default;
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
if (result.empty()) {
result = std::invoke(functor, *base);
@@ -383,40 +384,40 @@ struct MappingIterator
return *result;
}
MappingIterator& operator++() noexcept
MappingIterator& operator++() MIJIN_NOEXCEPT
{
++base;
result.reset();
return *this;
}
MappingIterator operator++(int) noexcept
MappingIterator operator++(int) MIJIN_NOEXCEPT
{
MappingIterator copy(*this);
++(*this);
return copy;
}
MappingIterator& operator--() noexcept
MappingIterator& operator--() MIJIN_NOEXCEPT
{
--base;
result.reset();
return *this;
}
MappingIterator operator--(int) noexcept
MappingIterator operator--(int) MIJIN_NOEXCEPT
{
MappingIterator copy(*this);
--(*this);
return copy;
}
bool operator==(const MappingIterator& other) const noexcept
bool operator==(const MappingIterator& other) const MIJIN_NOEXCEPT
{
return base == other.base; // TODO: compare functor? -> doesn't always work and may be useless
}
bool operator!=(const MappingIterator& other) const noexcept
bool operator!=(const MappingIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -431,17 +432,17 @@ struct MappingRange : RangeAdapter
RangeRef<TIterable> base;
TFunctor functor;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return MappingIterator(base.begin(), functor);
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return MappingIterator(base.end(), functor);
}
[[nodiscard]] bool empty() const noexcept {
[[nodiscard]] bool empty() const MIJIN_NOEXCEPT {
return base.begin() == base.end();
}
};
@@ -472,7 +473,7 @@ struct OptionalMappingIterator
TFunctor functor;
mutable optional_type result; // must be mutable so dereferencing can stay const, not nice :/
OptionalMappingIterator(TIterator base_, TIterator end_, TFunctor functor_) noexcept : base(base_), end(end_), functor(std::move(functor_)) {
OptionalMappingIterator(TIterator base_, TIterator end_, TFunctor functor_) MIJIN_NOEXCEPT : base(base_), end(end_), functor(std::move(functor_)) {
if (base != end)
{
result = functor(*base);
@@ -481,18 +482,18 @@ struct OptionalMappingIterator
}
}
}
OptionalMappingIterator(const OptionalMappingIterator&) noexcept = default;
OptionalMappingIterator(OptionalMappingIterator&&) noexcept = default;
OptionalMappingIterator(const OptionalMappingIterator&) MIJIN_NOEXCEPT = default;
OptionalMappingIterator(OptionalMappingIterator&&) MIJIN_NOEXCEPT = default;
OptionalMappingIterator& operator=(const OptionalMappingIterator&) noexcept = default;
OptionalMappingIterator& operator=(OptionalMappingIterator&&) noexcept = default;
OptionalMappingIterator& operator=(const OptionalMappingIterator&) MIJIN_NOEXCEPT = default;
OptionalMappingIterator& operator=(OptionalMappingIterator&&) MIJIN_NOEXCEPT = default;
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
return *result;
}
OptionalMappingIterator& operator++() noexcept
OptionalMappingIterator& operator++() MIJIN_NOEXCEPT
{
do
{
@@ -502,19 +503,19 @@ struct OptionalMappingIterator
return *this;
}
OptionalMappingIterator operator++(int) noexcept
OptionalMappingIterator operator++(int) MIJIN_NOEXCEPT
{
OptionalMappingIterator copy(*this);
++(*this);
return copy;
}
bool operator==(const OptionalMappingIterator& other) const noexcept
bool operator==(const OptionalMappingIterator& other) const MIJIN_NOEXCEPT
{
return base == other.base && end == other.end; // TODO: compare functor? -> doesn't always work and may be useless
}
bool operator!=(const OptionalMappingIterator& other) const noexcept
bool operator!=(const OptionalMappingIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -529,12 +530,12 @@ struct OptionalMappingRange : RangeAdapter
RangeRef<TIterable> base;
TFunctor functor;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return OptionalMappingIterator(base.begin(), base.end(), functor);
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return OptionalMappingIterator(base.end(), base.end(), functor);
}
@@ -561,23 +562,23 @@ struct FilteringIterator
TIterator end;
TPredicate predicate;
FilteringIterator(TIterator base_, TIterator end_, TPredicate predicate_) noexcept : base(base_), end(end_), predicate(std::move(predicate_)) {
FilteringIterator(TIterator base_, TIterator end_, TPredicate predicate_) MIJIN_NOEXCEPT : base(base_), end(end_), predicate(std::move(predicate_)) {
if (base != end && !predicate(*base)) {
++(*this);
}
}
FilteringIterator(const FilteringIterator&) noexcept = default;
FilteringIterator(FilteringIterator&&) noexcept = default;
FilteringIterator(const FilteringIterator&) MIJIN_NOEXCEPT = default;
FilteringIterator(FilteringIterator&&) MIJIN_NOEXCEPT = default;
FilteringIterator& operator=(const FilteringIterator&) noexcept = default;
FilteringIterator& operator=(FilteringIterator&&) noexcept = default;
FilteringIterator& operator=(const FilteringIterator&) MIJIN_NOEXCEPT = default;
FilteringIterator& operator=(FilteringIterator&&) MIJIN_NOEXCEPT = default;
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
return *base;
}
FilteringIterator& operator++() noexcept
FilteringIterator& operator++() MIJIN_NOEXCEPT
{
do
{
@@ -586,19 +587,19 @@ struct FilteringIterator
return *this;
}
FilteringIterator operator++(int) noexcept
FilteringIterator operator++(int) MIJIN_NOEXCEPT
{
FilteringIterator copy(*this);
++(*this);
return copy;
}
bool operator==(const FilteringIterator& other) const noexcept
bool operator==(const FilteringIterator& other) const MIJIN_NOEXCEPT
{
return base == other.base && end == other.end; // TODO: compare predicate?
}
bool operator!=(const FilteringIterator& other) const noexcept
bool operator!=(const FilteringIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -613,12 +614,12 @@ struct FilteringRange : RangeAdapter
RangeRef<TIterable> base;
TPredicate predicate;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return FilteringIterator(base.begin(), base.end(), predicate);
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return FilteringIterator(base.end(), base.end(), predicate);
}
@@ -647,13 +648,13 @@ struct ChainingIterator
TSecondIterator secondBase;
TSecondIterator secondBegin;
ChainingIterator(TFirstIterator firstBase_, TFirstIterator firstEnd_, TSecondIterator secondBase_, TSecondIterator secondBegin_) noexcept
ChainingIterator(TFirstIterator firstBase_, TFirstIterator firstEnd_, TSecondIterator secondBase_, TSecondIterator secondBegin_) MIJIN_NOEXCEPT
: firstBase(firstBase_), firstEnd(firstEnd_), secondBase(secondBase_), secondBegin(secondBegin_) {}
ChainingIterator(const ChainingIterator&) noexcept = default;
ChainingIterator(const ChainingIterator&) MIJIN_NOEXCEPT = default;
ChainingIterator& operator=(const ChainingIterator&) noexcept = default;
ChainingIterator& operator=(const ChainingIterator&) MIJIN_NOEXCEPT = default;
pointer operator->() const noexcept
pointer operator->() const MIJIN_NOEXCEPT
{
if (firstBase == firstEnd)
{
@@ -662,7 +663,7 @@ struct ChainingIterator
return &*firstBase;
}
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
if (firstBase == firstEnd)
{
@@ -671,7 +672,7 @@ struct ChainingIterator
return *firstBase;
}
ChainingIterator& operator++() noexcept
ChainingIterator& operator++() MIJIN_NOEXCEPT
{
if (firstBase == firstEnd) {
++secondBase;
@@ -682,14 +683,14 @@ struct ChainingIterator
return *this;
}
ChainingIterator operator++(int) noexcept
ChainingIterator operator++(int) MIJIN_NOEXCEPT
{
ChainingIterator copy(*this);
++(*this);
return copy;
}
ChainingIterator& operator--() noexcept
ChainingIterator& operator--() MIJIN_NOEXCEPT
{
if (secondBase == secondBegin) {
--firstBase;
@@ -700,19 +701,19 @@ struct ChainingIterator
return *this;
}
ChainingIterator operator--(int) noexcept
ChainingIterator operator--(int) MIJIN_NOEXCEPT
{
ChainingIterator copy(*this);
--(*this);
return copy;
}
bool operator==(const ChainingIterator& other) const noexcept
bool operator==(const ChainingIterator& other) const MIJIN_NOEXCEPT
{
return firstBase == other.firstBase && secondBase == other.secondBase; // should be enough
}
bool operator!=(const ChainingIterator& other) const noexcept
bool operator!=(const ChainingIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -726,12 +727,12 @@ struct ChainedRange : RangeAdapter
RangeRef<TFirstRange> first;
RangeRef<TSecondRange> second;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return ChainingIterator(first.begin(), first.end(), second.begin(), second.begin());
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return ChainingIterator(first.end(), first.end(), second.end(), second.begin());
}
@@ -764,23 +765,23 @@ struct TypeFilteringIterator
TIterator base;
TIterator end;
TypeFilteringIterator(TIterator base_, TIterator end_) noexcept : base(base_), end(end_) {
TypeFilteringIterator(TIterator base_, TIterator end_) MIJIN_NOEXCEPT : base(base_), end(end_) {
if (base != end && !isCastable()) {
++(*this);
}
}
TypeFilteringIterator(const TypeFilteringIterator&) noexcept = default;
TypeFilteringIterator(TypeFilteringIterator&&) noexcept = default;
TypeFilteringIterator(const TypeFilteringIterator&) MIJIN_NOEXCEPT = default;
TypeFilteringIterator(TypeFilteringIterator&&) MIJIN_NOEXCEPT = default;
TypeFilteringIterator& operator=(const TypeFilteringIterator&) noexcept = default;
TypeFilteringIterator& operator=(TypeFilteringIterator&&) noexcept = default;
TypeFilteringIterator& operator=(const TypeFilteringIterator&) MIJIN_NOEXCEPT = default;
TypeFilteringIterator& operator=(TypeFilteringIterator&&) MIJIN_NOEXCEPT = default;
reference operator*() const noexcept
reference operator*() const MIJIN_NOEXCEPT
{
return static_cast<reference>(*base);
}
TypeFilteringIterator& operator++() noexcept
TypeFilteringIterator& operator++() MIJIN_NOEXCEPT
{
do
{
@@ -789,19 +790,19 @@ struct TypeFilteringIterator
return *this;
}
TypeFilteringIterator operator++(int) noexcept
TypeFilteringIterator operator++(int) MIJIN_NOEXCEPT
{
FilteringIterator copy(*this);
++(*this);
return copy;
}
bool operator==(const TypeFilteringIterator& other) const noexcept
bool operator==(const TypeFilteringIterator& other) const MIJIN_NOEXCEPT
{
return base == other.base && end == other.end;
}
bool operator!=(const TypeFilteringIterator& other) const noexcept
bool operator!=(const TypeFilteringIterator& other) const MIJIN_NOEXCEPT
{
return !(*this == other);
}
@@ -827,12 +828,12 @@ struct TypeFilteringRange : RangeAdapter
RangeRef<TIterable> iterable;
auto begin() const noexcept
auto begin() const MIJIN_NOEXCEPT
{
return TypeFilteringIterator<TType, decltype(iterable.begin())>(iterable.begin(), iterable.end());
}
auto end() const noexcept
auto end() const MIJIN_NOEXCEPT
{
return TypeFilteringIterator<TType, decltype(iterable.begin())>(iterable.end(), iterable.end());
}

View File

@@ -47,7 +47,7 @@ std::mutex gDlErrorMutex; // dlerror may not be thread-safe
// public functions
//
Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept
Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) MIJIN_NOEXCEPT
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
const std::unique_lock dlErrorLock(gDlErrorMutex);
@@ -67,7 +67,7 @@ Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept
#endif
}
bool closeSharedLibrary(const LibraryHandle library) noexcept
bool closeSharedLibrary(const LibraryHandle library) MIJIN_NOEXCEPT
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
return dlclose(library.data) == 0;
@@ -77,7 +77,7 @@ bool closeSharedLibrary(const LibraryHandle library) noexcept
#endif
}
void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept
void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) MIJIN_NOEXCEPT
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
return dlsym(library.data, symbolName);
@@ -88,7 +88,7 @@ void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName)
#endif
}
void setCurrentThreadName(const char* threadName) noexcept
void setCurrentThreadName(const char* threadName) MIJIN_NOEXCEPT
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
pthread_setname_np(pthread_self(), threadName);
@@ -97,7 +97,7 @@ void setCurrentThreadName(const char* threadName) noexcept
#endif
}
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) MIJIN_NOEXCEPT
{
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
return "lib" + std::string(libraryName) + ".so";

View File

@@ -9,6 +9,7 @@
#include <string_view>
#include <utility>
#include "../detect.hpp"
#include "../internal/common.hpp"
#include "../types/result.hpp"
namespace mijin
@@ -39,8 +40,8 @@ struct LibraryHandle
{
void* data = nullptr;
constexpr operator bool() const noexcept { return data != nullptr; }
constexpr bool operator!() const noexcept { return data == nullptr; }
constexpr operator bool() const MIJIN_NOEXCEPT { return data != nullptr; }
constexpr bool operator!() const MIJIN_NOEXCEPT { return data == nullptr; }
};
class SharedLibrary
@@ -48,43 +49,43 @@ class SharedLibrary
private:
LibraryHandle mHandle;
public:
SharedLibrary() noexcept = default;
SharedLibrary() MIJIN_NOEXCEPT = default;
SharedLibrary(const SharedLibrary&) = delete;
SharedLibrary(SharedLibrary&& other) noexcept : mHandle(std::exchange(other.mHandle, {})) {}
inline ~SharedLibrary() noexcept;
SharedLibrary(SharedLibrary&& other) MIJIN_NOEXCEPT : mHandle(std::exchange(other.mHandle, {})) {}
inline ~SharedLibrary() MIJIN_NOEXCEPT;
SharedLibrary& operator=(const SharedLibrary&) = delete;
SharedLibrary& operator=(SharedLibrary&& other) noexcept
SharedLibrary& operator=(SharedLibrary&& other) MIJIN_NOEXCEPT
{
mHandle = std::exchange(other.mHandle, {});
return *this;
}
constexpr operator bool() const noexcept { return static_cast<bool>(mHandle); }
constexpr bool operator!() const noexcept { return !mHandle; }
constexpr operator bool() const MIJIN_NOEXCEPT { return static_cast<bool>(mHandle); }
constexpr bool operator!() const MIJIN_NOEXCEPT { return !mHandle; }
[[nodiscard]] inline Result<bool> open(std::string_view libraryFile) noexcept;
inline bool close() noexcept;
[[nodiscard]] inline void* loadSymbol(const char* symbolName) noexcept;
[[nodiscard]] inline Result<bool> open(std::string_view libraryFile) MIJIN_NOEXCEPT;
inline bool close() MIJIN_NOEXCEPT;
[[nodiscard]] inline void* loadSymbol(const char* symbolName) MIJIN_NOEXCEPT;
};
//
// public functions
//
[[nodiscard]] Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept;
bool closeSharedLibrary(const LibraryHandle library) noexcept;
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept;
void setCurrentThreadName(const char* threadName) noexcept;
[[nodiscard]] Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) MIJIN_NOEXCEPT;
bool closeSharedLibrary(const LibraryHandle library) MIJIN_NOEXCEPT;
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) MIJIN_NOEXCEPT;
void setCurrentThreadName(const char* threadName) MIJIN_NOEXCEPT;
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept;
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) MIJIN_NOEXCEPT;
SharedLibrary::~SharedLibrary() noexcept
SharedLibrary::~SharedLibrary() MIJIN_NOEXCEPT
{
close();
}
Result<bool> SharedLibrary::open(std::string_view libraryFile) noexcept
Result<bool> SharedLibrary::open(std::string_view libraryFile) MIJIN_NOEXCEPT
{
close();
Result<LibraryHandle> openResult = openSharedLibrary(libraryFile);
@@ -96,7 +97,7 @@ Result<bool> SharedLibrary::open(std::string_view libraryFile) noexcept
return ResultError(openResult.getError());
}
bool SharedLibrary::close() noexcept
bool SharedLibrary::close() MIJIN_NOEXCEPT
{
if (mHandle)
{
@@ -105,7 +106,7 @@ bool SharedLibrary::close() noexcept
return false;
}
void* SharedLibrary::loadSymbol(const char* symbolName) noexcept
void* SharedLibrary::loadSymbol(const char* symbolName) MIJIN_NOEXCEPT
{
return loadSymbolFromLibrary(mHandle, symbolName);
}

View File

@@ -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)));
}

View File

@@ -5,6 +5,7 @@
#include <functional>
#include "./common_macros.hpp"
#include "../internal/common.hpp"
#define MIJIN_SCOPE_EXIT_NAMED(name) \
const mijin::ScopeExitGuard name = [&]()
@@ -19,20 +20,20 @@ private:
mutable std::function<void(void)> func; // variable is declared const to make clang-tidy happy, but we still want to be able to reset()
public:
template<typename TFunc>
inline ScopeExitGuard(TFunc&& func_) noexcept : func(std::forward<TFunc>(func_)) {}
ScopeExitGuard(const ScopeExitGuard&) noexcept = delete;
ScopeExitGuard(ScopeExitGuard&&) noexcept = delete;
inline ~ScopeExitGuard() noexcept
inline ScopeExitGuard(TFunc&& func_) MIJIN_NOEXCEPT : func(std::forward<TFunc>(func_)) {}
ScopeExitGuard(const ScopeExitGuard&) = delete;
ScopeExitGuard(ScopeExitGuard&&) = delete;
inline ~ScopeExitGuard() MIJIN_NOEXCEPT
{
if (func) {
func();
}
}
ScopeExitGuard& operator=(const ScopeExitGuard&) noexcept = delete;
ScopeExitGuard& operator=(ScopeExitGuard&&) noexcept = delete;
ScopeExitGuard& operator=(const ScopeExitGuard&) = delete;
ScopeExitGuard& operator=(ScopeExitGuard&&) = delete;
inline void reset() const noexcept
inline void reset() const MIJIN_NOEXCEPT
{
func = {};
}

View File

@@ -16,6 +16,7 @@
#include <vector>
#include "./iterators.hpp"
#include "../internal/common.hpp"
namespace mijin
{
@@ -144,7 +145,7 @@ std::vector<std::basic_string_view<TChar, TTraits>> splitImpl(std::basic_string_
}
template<typename TChar, typename TTraitsA, typename TTraitsB>
bool equalsIgnoreCaseImpl(std::basic_string_view<TChar, TTraitsA> stringA, std::basic_string_view<TChar, TTraitsB> stringB) noexcept
bool equalsIgnoreCaseImpl(std::basic_string_view<TChar, TTraitsA> stringA, std::basic_string_view<TChar, TTraitsB> stringB) MIJIN_NOEXCEPT
{
if (stringA.size() != stringB.size())
{
@@ -243,7 +244,7 @@ auto trim(TString&& string)
}
template<typename TLeft, typename TRight>
[[nodiscard]] bool equalsIgnoreCase(TLeft&& left, TRight&& right) noexcept
[[nodiscard]] bool equalsIgnoreCase(TLeft&& left, TRight&& right) MIJIN_NOEXCEPT
{
return detail::equalsIgnoreCaseImpl(std::string_view(left), std::string_view(right));
}
@@ -287,7 +288,7 @@ constexpr auto toUpper(TArgs&&... args)
template<typename TNumber>
[[nodiscard]]
constexpr bool toNumber(std::string_view stringView, TNumber& outNumber, int base = 10) noexcept
constexpr bool toNumber(std::string_view stringView, TNumber& outNumber, int base = 10) MIJIN_NOEXCEPT
{
const char* start = &*stringView.begin();
const char* end = start + stringView.size();
@@ -297,7 +298,7 @@ constexpr bool toNumber(std::string_view stringView, TNumber& outNumber, int bas
template<typename TChar, typename TTraits, typename TNumber>
[[nodiscard]]
constexpr bool toNumber(std::basic_string_view<TChar, TTraits> stringView, TNumber& outNumber, int base = 10) noexcept requires (!std::is_same_v<TChar, char>)
constexpr bool toNumber(std::basic_string_view<TChar, TTraits> stringView, TNumber& outNumber, int base = 10) MIJIN_NOEXCEPT requires (!std::is_same_v<TChar, char>)
{
std::string asString;
asString.resize(stringView.size());
@@ -312,7 +313,7 @@ struct Join
{
const char* delimiter;
explicit Join(const char* delimiter_) noexcept : delimiter(delimiter_) {}
explicit Join(const char* delimiter_) MIJIN_NOEXCEPT : delimiter(delimiter_) {}
};
template<typename TIterable>