resource: prepare to remove ENTT_NOEXCEPT[_IF]

This commit is contained in:
Michele Caini
2022-05-06 08:23:30 +02:00
parent cb02f0621c
commit 2065c4294f
2 changed files with 56 additions and 58 deletions

View File

@@ -8,7 +8,6 @@
#include <tuple>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "../container/dense_map.hpp"
#include "../core/compressed_pair.hpp"
#include "../core/fwd.hpp"
@@ -39,108 +38,108 @@ public:
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;
constexpr resource_cache_iterator() ENTT_NOEXCEPT = default;
constexpr resource_cache_iterator() noexcept = default;
constexpr resource_cache_iterator(const It iter) ENTT_NOEXCEPT
constexpr resource_cache_iterator(const It iter) noexcept
: it{iter} {}
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
constexpr resource_cache_iterator(const resource_cache_iterator<std::remove_const_t<Type>, Other> &other) ENTT_NOEXCEPT
constexpr resource_cache_iterator(const resource_cache_iterator<std::remove_const_t<Type>, Other> &other) noexcept
: it{other.it} {}
constexpr resource_cache_iterator &operator++() ENTT_NOEXCEPT {
constexpr resource_cache_iterator &operator++() noexcept {
return ++it, *this;
}
constexpr resource_cache_iterator operator++(int) ENTT_NOEXCEPT {
constexpr resource_cache_iterator operator++(int) noexcept {
resource_cache_iterator orig = *this;
return ++(*this), orig;
}
constexpr resource_cache_iterator &operator--() ENTT_NOEXCEPT {
constexpr resource_cache_iterator &operator--() noexcept {
return --it, *this;
}
constexpr resource_cache_iterator operator--(int) ENTT_NOEXCEPT {
constexpr resource_cache_iterator operator--(int) noexcept {
resource_cache_iterator orig = *this;
return operator--(), orig;
}
constexpr resource_cache_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
constexpr resource_cache_iterator &operator+=(const difference_type value) noexcept {
it += value;
return *this;
}
constexpr resource_cache_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
constexpr resource_cache_iterator operator+(const difference_type value) const noexcept {
resource_cache_iterator copy = *this;
return (copy += value);
}
constexpr resource_cache_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
constexpr resource_cache_iterator &operator-=(const difference_type value) noexcept {
return (*this += -value);
}
constexpr resource_cache_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
constexpr resource_cache_iterator operator-(const difference_type value) const noexcept {
return (*this + -value);
}
[[nodiscard]] constexpr reference operator[](const difference_type value) const ENTT_NOEXCEPT {
[[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept {
return {it[value].first, resource<Type>{it[value].second}};
}
[[nodiscard]] constexpr reference operator*() const ENTT_NOEXCEPT {
[[nodiscard]] constexpr reference operator*() const noexcept {
return (*this)[0];
}
[[nodiscard]] constexpr pointer operator->() const ENTT_NOEXCEPT {
[[nodiscard]] constexpr pointer operator->() const noexcept {
return operator*();
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
friend constexpr std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
friend constexpr std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) noexcept;
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
friend constexpr bool operator==(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
friend constexpr bool operator==(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) noexcept;
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
friend constexpr bool operator<(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) ENTT_NOEXCEPT;
friend constexpr bool operator<(const resource_cache_iterator<TLhs, ILhs> &, const resource_cache_iterator<TRhs, IRhs> &) noexcept;
private:
It it;
};
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr std::ptrdiff_t operator-(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return lhs.it - rhs.it;
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator==(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator==(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return lhs.it == rhs.it;
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator!=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator!=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return !(lhs == rhs);
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator<(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator<(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return lhs.it < rhs.it;
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator>(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator>(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return rhs < lhs;
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator<=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator<=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return !(lhs > rhs);
}
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
[[nodiscard]] constexpr bool operator>=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] constexpr bool operator>=(const resource_cache_iterator<TLhs, ILhs> &lhs, const resource_cache_iterator<TRhs, IRhs> &rhs) noexcept {
return !(lhs < rhs);
}
@@ -235,7 +234,7 @@ public:
* @brief Returns the associated allocator.
* @return The associated allocator.
*/
[[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
[[nodiscard]] constexpr allocator_type get_allocator() const noexcept {
return pool.first().get_allocator();
}
@@ -247,17 +246,17 @@ public:
*
* @return An iterator to the first instance of the internal cache.
*/
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
[[nodiscard]] const_iterator cbegin() const noexcept {
return pool.first().begin();
}
/*! @copydoc cbegin */
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
[[nodiscard]] const_iterator begin() const noexcept {
return cbegin();
}
/*! @copydoc begin */
[[nodiscard]] iterator begin() ENTT_NOEXCEPT {
[[nodiscard]] iterator begin() noexcept {
return pool.first().begin();
}
@@ -271,17 +270,17 @@ public:
* @return An iterator to the element following the last instance of the
* internal cache.
*/
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
[[nodiscard]] const_iterator cend() const noexcept {
return pool.first().end();
}
/*! @copydoc cend */
[[nodiscard]] const_iterator end() const ENTT_NOEXCEPT {
[[nodiscard]] const_iterator end() const noexcept {
return cend();
}
/*! @copydoc end */
[[nodiscard]] iterator end() ENTT_NOEXCEPT {
[[nodiscard]] iterator end() noexcept {
return pool.first().end();
}
@@ -289,7 +288,7 @@ public:
* @brief Returns true if a cache contains no resources, false otherwise.
* @return True if the cache contains no resources, false otherwise.
*/
[[nodiscard]] bool empty() const ENTT_NOEXCEPT {
[[nodiscard]] bool empty() const noexcept {
return pool.first().empty();
}
@@ -297,12 +296,12 @@ public:
* @brief Number of resources managed by a cache.
* @return Number of resources currently stored.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
[[nodiscard]] size_type size() const noexcept {
return pool.first().size();
}
/*! @brief Clears a cache. */
void clear() ENTT_NOEXCEPT {
void clear() noexcept {
pool.first().clear();
}

View File

@@ -4,7 +4,6 @@
#include <memory>
#include <type_traits>
#include <utility>
#include "../config/config.h"
#include "fwd.hpp"
namespace entt {
@@ -30,21 +29,21 @@ class resource {
public:
/*! @brief Default constructor. */
resource() ENTT_NOEXCEPT
resource() noexcept
: value{} {}
/**
* @brief Creates a handle from a weak pointer, namely a resource.
* @param res A weak pointer to a resource.
*/
explicit resource(std::shared_ptr<Type> res) ENTT_NOEXCEPT
explicit resource(std::shared_ptr<Type> res) noexcept
: value{std::move(res)} {}
/*! @brief Default copy constructor. */
resource(const resource &) ENTT_NOEXCEPT = default;
resource(const resource &) noexcept = default;
/*! @brief Default move constructor. */
resource(resource &&) ENTT_NOEXCEPT = default;
resource(resource &&) noexcept = default;
/**
* @brief Aliasing constructor.
@@ -53,7 +52,7 @@ public:
* @param res Unrelated and unmanaged resources.
*/
template<typename Other>
resource(const resource<Other> &other, Type &res) ENTT_NOEXCEPT
resource(const resource<Other> &other, Type &res) noexcept
: value{other.value, std::addressof(res)} {}
/**
@@ -62,7 +61,7 @@ public:
* @param other The handle to copy from.
*/
template<typename Other, typename = std::enable_if_t<is_acceptable_v<Other>>>
resource(const resource<Other> &other) ENTT_NOEXCEPT
resource(const resource<Other> &other) noexcept
: value{other.value} {}
/**
@@ -71,20 +70,20 @@ public:
* @param other The handle to move from.
*/
template<typename Other, typename = std::enable_if_t<is_acceptable_v<Other>>>
resource(resource<Other> &&other) ENTT_NOEXCEPT
resource(resource<Other> &&other) noexcept
: value{std::move(other.value)} {}
/**
* @brief Default copy assignment operator.
* @return This resource handle.
*/
resource &operator=(const resource &) ENTT_NOEXCEPT = default;
resource &operator=(const resource &) noexcept = default;
/**
* @brief Default move assignment operator.
* @return This resource handle.
*/
resource &operator=(resource &&) ENTT_NOEXCEPT = default;
resource &operator=(resource &&) noexcept = default;
/**
* @brief Copy assignment operator from foreign handle.
@@ -94,7 +93,7 @@ public:
*/
template<typename Other>
std::enable_if_t<is_acceptable_v<Other>, resource &>
operator=(const resource<Other> &other) ENTT_NOEXCEPT {
operator=(const resource<Other> &other) noexcept {
value = other.value;
return *this;
}
@@ -107,7 +106,7 @@ public:
*/
template<typename Other>
std::enable_if_t<is_acceptable_v<Other>, resource &>
operator=(resource<Other> &&other) ENTT_NOEXCEPT {
operator=(resource<Other> &&other) noexcept {
value = std::move(other.value);
return *this;
}
@@ -120,12 +119,12 @@ public:
*
* @return A reference to the managed resource.
*/
[[nodiscard]] Type &operator*() const ENTT_NOEXCEPT {
[[nodiscard]] Type &operator*() const noexcept {
return *value;
}
/*! @copydoc operator* */
[[nodiscard]] operator Type &() const ENTT_NOEXCEPT {
[[nodiscard]] operator Type &() const noexcept {
return *value;
}
@@ -133,7 +132,7 @@ public:
* @brief Returns a pointer to the managed resource.
* @return A pointer to the managed resource.
*/
[[nodiscard]] Type *operator->() const ENTT_NOEXCEPT {
[[nodiscard]] Type *operator->() const noexcept {
return value.get();
}
@@ -141,7 +140,7 @@ public:
* @brief Returns true if a handle contains a resource, false otherwise.
* @return True if the handle contains a resource, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
[[nodiscard]] explicit operator bool() const noexcept {
return static_cast<bool>(value);
}
@@ -149,7 +148,7 @@ public:
* @brief Returns the number of handles pointing the same resource.
* @return The number of handles pointing the same resource.
*/
[[nodiscard]] long use_count() const ENTT_NOEXCEPT {
[[nodiscard]] long use_count() const noexcept {
return value.use_count();
}
@@ -166,7 +165,7 @@ private:
* @return True if both handles refer to the same resource, false otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator==(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator==(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return (std::addressof(*lhs) == std::addressof(*rhs));
}
@@ -179,7 +178,7 @@ template<typename Res, typename Other>
* @return False if both handles refer to the same registry, true otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator!=(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator!=(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return !(lhs == rhs);
}
@@ -192,7 +191,7 @@ template<typename Res, typename Other>
* @return True if the first handle is less than the second, false otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator<(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator<(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return (std::addressof(*lhs) < std::addressof(*rhs));
}
@@ -205,7 +204,7 @@ template<typename Res, typename Other>
* @return True if the first handle is greater than the second, false otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator>(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator>(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return (std::addressof(*lhs) > std::addressof(*rhs));
}
@@ -219,7 +218,7 @@ template<typename Res, typename Other>
* otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator<=(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator<=(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return !(lhs > rhs);
}
@@ -233,7 +232,7 @@ template<typename Res, typename Other>
* false otherwise.
*/
template<typename Res, typename Other>
[[nodiscard]] bool operator>=(const resource<Res> &lhs, const resource<Other> &rhs) ENTT_NOEXCEPT {
[[nodiscard]] bool operator>=(const resource<Res> &lhs, const resource<Other> &rhs) noexcept {
return !(lhs < rhs);
}