diff options
author | 2024-02-05 18:04:22 +0000 | |
---|---|---|
committer | 2024-02-05 18:04:22 +0000 | |
commit | 32966b68450dcff461bc73d0da3cfb663b9968f4 (patch) | |
tree | 653e1b58f8e0420466bb80c081f887794f5c5adc /include/ftl | |
parent | f03f1222678fff2dc389e78daea8ed469be1b9ef (diff) | |
parent | d7629e7fc637efc2b5c9ad6f61ba5d96b40f8d16 (diff) |
Merge changes I3fc52c3d,I6bdcd983 into main
* changes:
FTL: Silence __VA_ARGS__ warning with empty arg
FTL: Fix SmallMap<K, V, 0>::try_emplace
Diffstat (limited to 'include/ftl')
-rw-r--r-- | include/ftl/fake_guard.h | 3 | ||||
-rw-r--r-- | include/ftl/small_map.h | 22 | ||||
-rw-r--r-- | include/ftl/small_vector.h | 19 |
3 files changed, 28 insertions, 16 deletions
diff --git a/include/ftl/fake_guard.h b/include/ftl/fake_guard.h index bacd1b29ef..e6012516fc 100644 --- a/include/ftl/fake_guard.h +++ b/include/ftl/fake_guard.h @@ -85,6 +85,5 @@ struct [[clang::scoped_lockable]] FakeGuard final { #define FTL_MAKE_FAKE_GUARD(arg1, arg2, guard, ...) guard -// The void argument suppresses a warning about zero variadic macro arguments. #define FTL_FAKE_GUARD(...) \ - FTL_MAKE_FAKE_GUARD(__VA_ARGS__, FTL_FAKE_GUARD2, FTL_FAKE_GUARD1, void)(__VA_ARGS__) + FTL_MAKE_FAKE_GUARD(__VA_ARGS__, FTL_FAKE_GUARD2, FTL_FAKE_GUARD1, )(__VA_ARGS__) diff --git a/include/ftl/small_map.h b/include/ftl/small_map.h index 49cde7fedc..83d5967464 100644 --- a/include/ftl/small_map.h +++ b/include/ftl/small_map.h @@ -107,12 +107,20 @@ class SmallMap final { template <typename Q, typename W, std::size_t M, typename E> SmallMap(SmallMap<Q, W, M, E> other) : map_(std::move(other.map_)) {} + static constexpr size_type static_capacity() { return N; } + size_type max_size() const { return map_.max_size(); } size_type size() const { return map_.size(); } bool empty() const { return map_.empty(); } // Returns whether the map is backed by static or dynamic storage. - bool dynamic() const { return map_.dynamic(); } + bool dynamic() const { + if constexpr (static_capacity() > 0) { + return map_.dynamic(); + } else { + return true; + } + } iterator begin() { return map_.begin(); } const_iterator begin() const { return cbegin(); } @@ -171,9 +179,15 @@ class SmallMap final { return {it, false}; } - auto& ref = map_.emplace_back(std::piecewise_construct, std::forward_as_tuple(key), - std::forward_as_tuple(std::forward<Args>(args)...)); - return {&ref, true}; + decltype(auto) ref_or_it = + map_.emplace_back(std::piecewise_construct, std::forward_as_tuple(key), + std::forward_as_tuple(std::forward<Args>(args)...)); + + if constexpr (static_capacity() > 0) { + return {&ref_or_it, true}; + } else { + return {ref_or_it, true}; + } } // Replaces a mapping if it exists, and returns an iterator to it. Returns the end() iterator diff --git a/include/ftl/small_vector.h b/include/ftl/small_vector.h index 11294c3ac8..43e9fac5e2 100644 --- a/include/ftl/small_vector.h +++ b/include/ftl/small_vector.h @@ -124,30 +124,29 @@ class SmallVector final : details::ArrayTraits<T>, details::ArrayComparators<Sma DISPATCH(size_type, size, const) DISPATCH(bool, empty, const) - // noexcept to suppress warning about zero variadic macro arguments. - DISPATCH(iterator, begin, noexcept) + DISPATCH(iterator, begin, ) DISPATCH(const_iterator, begin, const) DISPATCH(const_iterator, cbegin, const) - DISPATCH(iterator, end, noexcept) + DISPATCH(iterator, end, ) DISPATCH(const_iterator, end, const) DISPATCH(const_iterator, cend, const) - DISPATCH(reverse_iterator, rbegin, noexcept) + DISPATCH(reverse_iterator, rbegin, ) DISPATCH(const_reverse_iterator, rbegin, const) DISPATCH(const_reverse_iterator, crbegin, const) - DISPATCH(reverse_iterator, rend, noexcept) + DISPATCH(reverse_iterator, rend, ) DISPATCH(const_reverse_iterator, rend, const) DISPATCH(const_reverse_iterator, crend, const) - DISPATCH(iterator, last, noexcept) + DISPATCH(iterator, last, ) DISPATCH(const_iterator, last, const) - DISPATCH(reference, front, noexcept) + DISPATCH(reference, front, ) DISPATCH(const_reference, front, const) - DISPATCH(reference, back, noexcept) + DISPATCH(reference, back, ) DISPATCH(const_reference, back, const) reference operator[](size_type i) { @@ -211,13 +210,13 @@ class SmallVector final : details::ArrayTraits<T>, details::ArrayComparators<Sma // // The last() and end() iterators are invalidated. // - DISPATCH(void, pop_back, noexcept) + DISPATCH(void, pop_back, ) // Removes all elements. // // All iterators are invalidated. // - DISPATCH(void, clear, noexcept) + DISPATCH(void, clear, ) #undef DISPATCH |