resource_cache: constexpr all the way (see #883)
This commit is contained in:
+24
-24
@@ -39,108 +39,108 @@ public:
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
resource_cache_iterator() ENTT_NOEXCEPT = default;
|
||||
constexpr resource_cache_iterator() ENTT_NOEXCEPT = default;
|
||||
|
||||
resource_cache_iterator(const It iter) ENTT_NOEXCEPT
|
||||
constexpr resource_cache_iterator(const It iter) ENTT_NOEXCEPT
|
||||
: it{iter} {}
|
||||
|
||||
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
|
||||
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) ENTT_NOEXCEPT
|
||||
: it{other.it} {}
|
||||
|
||||
resource_cache_iterator &operator++() ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator &operator++() ENTT_NOEXCEPT {
|
||||
return ++it, *this;
|
||||
}
|
||||
|
||||
resource_cache_iterator operator++(int) ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator operator++(int) ENTT_NOEXCEPT {
|
||||
resource_cache_iterator orig = *this;
|
||||
return ++(*this), orig;
|
||||
}
|
||||
|
||||
resource_cache_iterator &operator--() ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator &operator--() ENTT_NOEXCEPT {
|
||||
return --it, *this;
|
||||
}
|
||||
|
||||
resource_cache_iterator operator--(int) ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator operator--(int) ENTT_NOEXCEPT {
|
||||
resource_cache_iterator orig = *this;
|
||||
return operator--(), orig;
|
||||
}
|
||||
|
||||
resource_cache_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator &operator+=(const difference_type value) ENTT_NOEXCEPT {
|
||||
it += value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
resource_cache_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator operator+(const difference_type value) const ENTT_NOEXCEPT {
|
||||
resource_cache_iterator copy = *this;
|
||||
return (copy += value);
|
||||
}
|
||||
|
||||
resource_cache_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator &operator-=(const difference_type value) ENTT_NOEXCEPT {
|
||||
return (*this += -value);
|
||||
}
|
||||
|
||||
resource_cache_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
|
||||
constexpr resource_cache_iterator operator-(const difference_type value) const ENTT_NOEXCEPT {
|
||||
return (*this + -value);
|
||||
}
|
||||
|
||||
[[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr reference operator[](const difference_type value) const ENTT_NOEXCEPT {
|
||||
return {it[value].first, resource<Type>{it[value].second}};
|
||||
}
|
||||
|
||||
[[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr reference operator*() const ENTT_NOEXCEPT {
|
||||
return (*this)[0];
|
||||
}
|
||||
|
||||
[[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] constexpr pointer operator->() const ENTT_NOEXCEPT {
|
||||
return operator*();
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
friend 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> &) ENTT_NOEXCEPT;
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
friend 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> &) ENTT_NOEXCEPT;
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
friend 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> &) ENTT_NOEXCEPT;
|
||||
|
||||
private:
|
||||
It it;
|
||||
};
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return lhs.it - rhs.it;
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return lhs.it == rhs.it;
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return lhs.it < rhs.it;
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
template<typename TLhs, typename ILhs, typename TRhs, typename IRhs>
|
||||
[[nodiscard]] 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) ENTT_NOEXCEPT {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user