diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-06 22:56:56 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-06 22:56:56 +0100 |
commit | f0cccbe3285c039553e1fd8b5a5c7830d6087974 (patch) | |
tree | 57a0902484ec5c8ba3b9a8e7089ed42f58b6a580 /asl | |
parent | 54affafd86e2b7f387345c08e8c7285c775d75e5 (diff) |
Replace ASL_MOVE, ASL_FWD, and ASL_FWD_LIKE by their std:: equivalent
This is because some compiler stuff and diagnostics tools rely on those
symboles being what they are.
Diffstat (limited to 'asl')
30 files changed, 273 insertions, 213 deletions
diff --git a/asl/base/assert.cpp b/asl/base/assert.cpp index ecda20d..b96836b 100644 --- a/asl/base/assert.cpp +++ b/asl/base/assert.cpp @@ -4,7 +4,12 @@ #include "asl/base/assert.hpp" +#include "asl/base/meta.hpp" + +// NOLINTNEXTLINE(*-non-const-global-variables) static asl::AssertFailureHandler* s_handler = nullptr; + +// NOLINTNEXTLINE(*-non-const-global-variables) static void* s_user = nullptr; void asl::set_assert_failure_handler(AssertFailureHandler handler, void* user) diff --git a/asl/base/defer.hpp b/asl/base/defer.hpp index bc5d078..c9c08ba 100644 --- a/asl/base/defer.hpp +++ b/asl/base/defer.hpp @@ -18,14 +18,14 @@ class DeferCallback public: template<typename T> - explicit DeferCallback(T&& callback) : m_callback(ASL_FWD(callback)) + explicit DeferCallback(T&& callback) : m_callback(std::forward<T>(callback)) { } ASL_DELETE_COPY(DeferCallback); DeferCallback(DeferCallback&& other) : - m_callback(ASL_MOVE(other.m_callback)), m_moved(exchange(other.m_moved, true)) + m_callback(std::move(other.m_callback)), m_moved(exchange(other.m_moved, true)) { } @@ -42,7 +42,7 @@ struct DeferFactory template<invocable Callback> DeferCallback<Callback> operator<<(Callback&& callback) const { - return DeferCallback<Callback>(ASL_FWD(callback)); + return DeferCallback<Callback>(std::forward<Callback>(callback)); } }; diff --git a/asl/base/functional.hpp b/asl/base/functional.hpp index 9aeb485..509a2b2 100644 --- a/asl/base/functional.hpp +++ b/asl/base/functional.hpp @@ -11,22 +11,22 @@ namespace asl { template<typename... Args, typename C> constexpr auto invoke(is_func auto C::* f, auto&& self, Args&&... args) - -> decltype((self.*f)(ASL_FWD(args)...)) + -> decltype((self.*f)(std::forward<Args>(args)...)) requires requires { - (self.*f)(ASL_FWD(args)...); + (self.*f)(std::forward<Args>(args)...); } { - return (ASL_FWD(self).*f)(ASL_FWD(args)...); + return (std::forward<decltype(self)>(self).*f)(std::forward<Args>(args)...); } template<typename... Args, typename C> constexpr auto invoke(is_func auto C::* f, auto* self, Args&&... args) - -> decltype((self->*f)(ASL_FWD(args)...)) + -> decltype((self->*f)(std::forward<Args>(args)...)) requires requires { - (self->*f)(ASL_FWD(args)...); + (self->*f)(std::forward<Args>(args)...); } { - return (self->*f)(ASL_FWD(args)...); + return (self->*f)(std::forward<Args>(args)...); } template<typename... Args, typename C> @@ -37,7 +37,7 @@ constexpr auto invoke(is_object auto C::* m, auto&& self, Args&&...) requires { self.*m; } ) { - return ASL_FWD(self).*m; + return std::forward<decltype(self)>(self).*m; } template<typename... Args, typename C> @@ -53,12 +53,12 @@ constexpr auto invoke(is_object auto C::* m, auto* self, Args&&...) template<typename... Args> constexpr auto invoke(auto&& f, Args&&... args) - -> decltype(f(ASL_FWD(args)...)) + -> decltype(f(std::forward<Args>(args)...)) requires requires { - f(ASL_FWD(args)...); + f(std::forward<Args>(args)...); } { - return ASL_FWD(f)(ASL_FWD(args)...); + return std::forward<decltype(f)>(f)(std::forward<Args>(args)...); } template<typename Void, typename F, typename... Args> @@ -76,7 +76,7 @@ using invoke_result_t = _invoke_result_helper<void, F, Args...>::type; template<typename F, typename... Args> concept invocable = requires (F&& f, Args&&... args) { - invoke(ASL_FWD(f), ASL_FWD(args)...); + invoke(std::forward<F>(f), std::forward<Args>(args)...); }; } // namespace asl diff --git a/asl/base/utility.hpp b/asl/base/utility.hpp index 63f16b1..07f8b51 100644 --- a/asl/base/utility.hpp +++ b/asl/base/utility.hpp @@ -7,11 +7,36 @@ #include "asl/base/meta.hpp" #include "asl/base/assert.hpp" -#define ASL_MOVE(...) (static_cast<::asl::un_ref_t<decltype(__VA_ARGS__)>&&>(__VA_ARGS__)) +namespace std +{ + +template<typename T> +constexpr asl::un_ref_t<T>&& move(T&& t) noexcept // NOLINT +{ + return static_cast<asl::un_ref_t<T>&&>(t); +} + +template<typename T> +constexpr T&& forward(asl::un_ref_t<T>& t) noexcept // NOLINT +{ + return static_cast<T&&>(t); +} + +template< class T > +constexpr T&& forward(asl::un_ref_t<T>&& t) noexcept // NOLINT +{ + return static_cast<T&&>(t); +} + +template<typename T, typename U> +constexpr auto forward_like(U&& x) noexcept -> asl::copy_cref_t<T, U> // NOLINT +{ + using return_type = asl::copy_cref_t<T, U&&>; + return static_cast<return_type>(x); +} -#define ASL_FWD(expr_) (static_cast<decltype(expr_)&&>(expr_)) +} // namespace std -#define ASL_FWD_LIKE(ref_, expr_) (static_cast<::asl::copy_cref_t<ref_, decltype(expr_)&&>>(expr_)) namespace asl { @@ -22,16 +47,16 @@ static constexpr in_place_t in_place{}; template<moveable T> constexpr void swap(T& a, T& b) { - T tmp{ASL_MOVE(a)}; - a = ASL_MOVE(b); - b = ASL_MOVE(tmp); + T tmp{std::move(a)}; + a = std::move(b); + b = std::move(tmp); } template<typename T, typename U> T exchange(T& obj, U&& new_value) { - T old_value = ASL_MOVE(obj); - obj = ASL_FWD(new_value); + T old_value = std::move(obj); + obj = std::forward<U>(new_value); return old_value; } @@ -59,44 +84,46 @@ constexpr uint64_t round_up_pow2(uint64_t v) v -= 1; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v |= v >> 32; + v |= v >> 1U; + v |= v >> 2U; + v |= v >> 4U; + v |= v >> 8U; + v |= v >> 16U; + v |= v >> 32U; return v + 1; } constexpr bool is_pow2(isize_t v) { - return v > 0 && ((v - 1) & v) == 0; + return v > 0 && ((v - 1) & v) == 0; // NOLINT } +// NOLINTBEGIN(*-macro-parentheses) #define ASL_DELETE_COPY(T) \ T(const T&) = delete; \ - T& operator=(const T&) = delete; + T& operator=(const T&) = delete #define ASL_DELETE_MOVE(T) \ T(T&&) = delete; \ - T& operator=(T&&) = delete; + T& operator=(T&&) = delete #define ASL_DELETE_COPY_MOVE(T) \ - ASL_DELETE_COPY(T) \ + ASL_DELETE_COPY(T); \ ASL_DELETE_MOVE(T) #define ASL_DEFAULT_COPY(T) \ T(const T&) = default; \ - T& operator=(const T&) = default; + T& operator=(const T&) = default #define ASL_DEFAULT_MOVE(T) \ T(T&&) = default; \ - T& operator=(T&&) = default; + T& operator=(T&&) = default #define ASL_DEFAULT_COPY_MOVE(T) \ - ASL_DEFAULT_COPY(T) \ + ASL_DEFAULT_COPY(T); \ ASL_DEFAULT_MOVE(T) +// NOLINTEND(*-macro-parentheses) #define ASL_CONCAT2(A, B) A##B #define ASL_CONCAT(A, B) ASL_CONCAT2(A, B) diff --git a/asl/base/utility_tests.cpp b/asl/base/utility_tests.cpp index 20cdf97..7e54bb2 100644 --- a/asl/base/utility_tests.cpp +++ b/asl/base/utility_tests.cpp @@ -12,28 +12,28 @@ template<typename T> static constexpr int identify(T&&) { return 4; } struct IdentifySelf { - constexpr int get(this auto&& self) { return identify(ASL_FWD(self)); } + constexpr int get(this auto&& self) { return identify(std::forward<decltype(self)>(self)); } }; -static int get_const_lref(const IdentifySelf& i) { return ASL_FWD(i).get(); } -static int get_const_rref(const IdentifySelf&& i) { return ASL_FWD(i).get(); } -static int get_lref(IdentifySelf& i) { return ASL_FWD(i).get(); } -static int get_rref(IdentifySelf&& i) { return ASL_FWD(i).get(); } +static int get_const_lref(const IdentifySelf& i) { return i.get(); } +static int get_const_rref(const IdentifySelf&& i) { return std::move(i).get(); } // NOLINT +static int get_lref(IdentifySelf& i) { return i.get(); } +static int get_rref(IdentifySelf&& i) { return std::move(i).get(); } // NOLINT ASL_TEST(forward) { - IdentifySelf id; - ASL_TEST_EXPECT(get_const_lref(id) == 1); + IdentifySelf id{}; + ASL_TEST_EXPECT(get_const_lref(IdentifySelf{}) == 1); ASL_TEST_EXPECT(get_lref(id) == 3); - ASL_TEST_EXPECT(get_const_rref(ASL_MOVE(id)) == 2); - ASL_TEST_EXPECT(get_rref(ASL_MOVE(id)) == 4); + ASL_TEST_EXPECT(get_const_rref(IdentifySelf{}) == 2); + ASL_TEST_EXPECT(get_rref(IdentifySelf{}) == 4); } ASL_TEST(move) { IdentifySelf id; ASL_TEST_EXPECT(id.get() == 3); - ASL_TEST_EXPECT(ASL_MOVE(id).get() == 4); + ASL_TEST_EXPECT(IdentifySelf{}.get() == 4); } struct Level1 @@ -51,33 +51,33 @@ struct Level3 Level2 deeper; }; -static int get_const_lref(const Level3& i) { return ASL_FWD(i).deeper.deeper.id.get(); } -static int get_const_rref(const Level3&& i) { return ASL_FWD(i).deeper.deeper.id.get(); } -static int get_lref(Level3& i) { return ASL_FWD(i).deeper.deeper.id.get(); } -static int get_rref(Level3&& i) { return ASL_FWD(i).deeper.deeper.id.get(); } +static int get_const_lref(const Level3& i) { return i.deeper.deeper.id.get(); } +static int get_const_rref(const Level3&& i) { return std::move(i).deeper.deeper.id.get(); } +static int get_lref(Level3& i) { return i.deeper.deeper.id.get(); } +static int get_rref(Level3&& i) { return std::move(i).deeper.deeper.id.get(); } ASL_TEST(forward2) { Level3 id{}; ASL_TEST_EXPECT(get_const_lref(id) == 1); ASL_TEST_EXPECT(get_lref(id) == 3); - ASL_TEST_EXPECT(get_const_rref(ASL_MOVE(id)) == 2); - ASL_TEST_EXPECT(get_rref(ASL_MOVE(id)) == 4); + ASL_TEST_EXPECT(get_const_rref(Level3{}) == 2); + ASL_TEST_EXPECT(get_rref(Level3{}) == 4); } template<typename T> -static int test_fwd_like(T&& t) +static int test_fwd_like(T) // NOLINT { - IdentifySelf id; - return ASL_FWD_LIKE(decltype(t), id).get(); + const IdentifySelf id; + return std::forward_like<T>(id).get(); } ASL_TEST(forward_like) { int x{}; - ASL_TEST_EXPECT(test_fwd_like<const int&>(x) == 1); + ASL_TEST_EXPECT(test_fwd_like<const int&>(7) == 1); ASL_TEST_EXPECT(test_fwd_like<int&>(x) == 3); - ASL_TEST_EXPECT(test_fwd_like<const int&&>(ASL_MOVE(x)) == 2); - ASL_TEST_EXPECT(test_fwd_like<int&&>(ASL_MOVE(x)) == 4); + ASL_TEST_EXPECT(test_fwd_like<const int&&>(8) == 2); + ASL_TEST_EXPECT(test_fwd_like<int&&>(9) == 4); } diff --git a/asl/containers/buffer.hpp b/asl/containers/buffer.hpp index 8bdb63e..386b52a 100644 --- a/asl/containers/buffer.hpp +++ b/asl/containers/buffer.hpp @@ -170,7 +170,7 @@ private: if (assign) { - m_allocator = ASL_MOVE(other.m_allocator); + m_allocator = std::move(other.m_allocator); } } @@ -209,7 +209,7 @@ private: // NOLINTNEXTLINE(*-pointer-arithmetic) for (T* it = data_ptr + old_size; it < end; ++it) { - construct_at<T>(it, ASL_FWD(args)...); + construct_at<T>(it, std::forward<Args>(args)...); } } @@ -224,11 +224,11 @@ public: } explicit constexpr buffer(Allocator allocator) - : m_allocator{ASL_MOVE(allocator)} + : m_allocator{std::move(allocator)} {} explicit constexpr buffer(span<const T> s, Allocator allocator) - : m_allocator{ASL_MOVE(allocator)} + : m_allocator{std::move(allocator)} { copy_range(s); } @@ -242,9 +242,9 @@ public: constexpr buffer(buffer&& other) requires moveable<T> - : buffer(ASL_MOVE(other.m_allocator)) + : buffer(std::move(other.m_allocator)) { - move_from_other(ASL_MOVE(other), false); + move_from_other(std::move(other), false); } constexpr buffer& operator=(const buffer& other) @@ -259,7 +259,7 @@ public: requires moveable<T> { if (&other == this) { return *this; } - move_from_other(ASL_MOVE(other), true); + move_from_other(std::move(other), true); return *this; } @@ -381,7 +381,7 @@ public: requires constructible_from<T, decltype(args)&&...> { T* uninit = push_uninit(); - T* init = construct_at<T>(uninit, ASL_FWD(args)...); + T* init = construct_at<T>(uninit, std::forward<decltype(args)>(args)...); return *init; } @@ -410,12 +410,12 @@ public: return contiguous_iterator<type>{self.data() + self.size()}; } - constexpr operator span<const T>() const // NOLINT(*-explicit-conversions) + constexpr operator span<const T>() const // NOLINT(*explicit*) { return as_span(); } - constexpr operator span<T>() // NOLINT(*-explicit-conversions) + constexpr operator span<T>() // NOLINT(*explicit*) { return as_span(); } @@ -429,14 +429,14 @@ public: constexpr auto&& operator[](this auto&& self, isize_t i) { ASL_ASSERT(i >= 0 && i <= self.size()); - return ASL_FWD_LIKE(decltype(self), ASL_FWD(self).data()[i]); + return std::forward_like<decltype(self)>(std::forward<decltype(self)>(self).data()[i]); } template<typename H> requires hashable<T> friend H AslHashValue(H h, const buffer& b) { - return H::combine_contiguous(ASL_MOVE(h), b.as_span()); + return H::combine_contiguous(std::move(h), b.as_span()); } }; diff --git a/asl/containers/buffer_tests.cpp b/asl/containers/buffer_tests.cpp index 23fe5af..af79c92 100644 --- a/asl/containers/buffer_tests.cpp +++ b/asl/containers/buffer_tests.cpp @@ -275,7 +275,7 @@ ASL_TEST(move_construct_from_heap) buf.push(&d[2]); { - asl::buffer<DestructorObserver> buf2(ASL_MOVE(buf)); + asl::buffer<DestructorObserver> buf2(std::move(buf)); ASL_TEST_EXPECT(buf2.size() == 3); ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[1] == false); @@ -294,7 +294,7 @@ ASL_TEST(move_construct_inline_trivial) buf.push(1U); buf.push(2U); - asl::buffer<uint64_t> buf2(ASL_MOVE(buf)); + asl::buffer<uint64_t> buf2(std::move(buf)); ASL_TEST_EXPECT(buf2[0] == 1U); ASL_TEST_EXPECT(buf2[1] == 2U); @@ -310,7 +310,7 @@ ASL_TEST(move_construct_from_inline_non_trivial) buf.push(&d[1]); { - asl::buffer<DestructorObserver> buf2(ASL_MOVE(buf)); + asl::buffer<DestructorObserver> buf2(std::move(buf)); ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[1] == false); @@ -344,7 +344,7 @@ ASL_TEST(move_assign_from_heap) ASL_TEST_EXPECT(d[4] == false); ASL_TEST_EXPECT(d[5] == false); - buf2 = ASL_MOVE(buf); + buf2 = std::move(buf); ASL_TEST_EXPECT(buf.size() == 0); ASL_TEST_EXPECT(buf2.size() == 3); @@ -380,7 +380,7 @@ ASL_TEST(move_assign_trivial_heap_to_inline) buf2.push(5); ASL_TEST_EXPECT(alloc_count == 1); - buf = ASL_MOVE(buf2); + buf = std::move(buf2); ASL_TEST_EXPECT(alloc_count == 1); ASL_TEST_EXPECT(buf.size() == 3); @@ -405,7 +405,7 @@ ASL_TEST(move_assign_trivial_inline_to_heap) buf2.push(5); ASL_TEST_EXPECT(alloc_count == 1); - buf2 = ASL_MOVE(buf); + buf2 = std::move(buf); ASL_TEST_EXPECT(alloc_count == 1); ASL_TEST_EXPECT(buf.size() == 0); @@ -430,7 +430,7 @@ ASL_TEST(move_assign_inline_to_heap) buf2.push(&d[4]); buf2.push(&d[5]); - buf2 = ASL_MOVE(buf); + buf2 = std::move(buf); ASL_TEST_EXPECT(buf.size() == 0); ASL_TEST_EXPECT(buf2.size() == 2); @@ -466,7 +466,7 @@ ASL_TEST(move_assign_from_inline_incompatible_allocator) buf2.push(&d[4]); buf2.push(&d[5]); - buf2 = ASL_MOVE(buf); + buf2 = std::move(buf); ASL_TEST_EXPECT(buf.size() == 0); ASL_TEST_EXPECT(buf2.size() == 2); diff --git a/asl/containers/hash_map.hpp b/asl/containers/hash_map.hpp index 77e5512..cf2f0b2 100644 --- a/asl/containers/hash_map.hpp +++ b/asl/containers/hash_map.hpp @@ -77,7 +77,7 @@ public: constexpr hash_map() requires default_constructible<Allocator> = default; explicit constexpr hash_map(Allocator allocator) - : Base{ASL_MOVE(allocator)} + : Base{std::move(allocator)} {} hash_map(const hash_map&) requires copyable<K> && copyable<V> = default; @@ -122,7 +122,7 @@ public: { ASL_ASSERT((Base::m_tags[result.first_available_index] & Base::kHasValue) == 0); - Base::m_values[result.first_available_index].construct_unsafe(ASL_MOVE(Base::m_values[result.already_present_index].as_init_unsafe())); + Base::m_values[result.first_available_index].construct_unsafe(std::move(Base::m_values[result.already_present_index].as_init_unsafe())); Base::m_values[result.already_present_index].destroy_unsafe(); Base::m_tags[result.first_available_index] = result.tag; @@ -133,17 +133,17 @@ public: if constexpr (sizeof...(Args1) == 0 && assignable_from<V&, Arg0&&>) { - Base::m_values[result.first_available_index].as_init_unsafe().value = ASL_FWD(arg0); + Base::m_values[result.first_available_index].as_init_unsafe().value = std::forward<Arg0>(arg0); } else { - Base::m_values[result.first_available_index].as_init_unsafe().value = ASL_MOVE(V{ASL_FWD(arg0), ASL_FWD(args1)...}); + Base::m_values[result.first_available_index].as_init_unsafe().value = std::move(V{std::forward<Arg0>(arg0), std::forward<Args1>(args1)...}); } } else { ASL_ASSERT((Base::m_tags[result.first_available_index] & Base::kHasValue) == 0); - Base::m_values[result.first_available_index].construct_unsafe(ASL_FWD(key), V{ASL_FWD(arg0), ASL_FWD(args1)...}); + Base::m_values[result.first_available_index].construct_unsafe(std::forward<U>(key), V{std::forward<Arg0>(arg0), std::forward<Args1>(args1)...}); Base::m_tags[result.first_available_index] = result.tag; Base::m_size += 1; } diff --git a/asl/containers/hash_set.hpp b/asl/containers/hash_set.hpp index 6c46aac..61346fa 100644 --- a/asl/containers/hash_set.hpp +++ b/asl/containers/hash_set.hpp @@ -115,7 +115,7 @@ protected: *size += 1; } - values[result.first_available_index].construct_unsafe(ASL_MOVE(value)); + values[result.first_available_index].construct_unsafe(std::move(value)); tags[result.first_available_index] = result.tag; } @@ -144,7 +144,7 @@ protected: { if ((m_tags[i] & kHasValue) == 0) { continue; } - insert_inner(ASL_MOVE(m_values[i].as_init_unsafe()), new_tags, new_values, new_capacity, &new_size); + insert_inner(std::move(m_values[i].as_init_unsafe()), new_tags, new_values, new_capacity, &new_size); // Destroy now so that destroy() has less things to do m_values[i].destroy_unsafe(); @@ -312,7 +312,7 @@ public: {} explicit constexpr hash_set(Allocator allocator) - : m_allocator{ASL_MOVE(allocator)} + : m_allocator{std::move(allocator)} {} hash_set(const hash_set& other) @@ -339,7 +339,7 @@ public: , m_values{exchange(other.m_values, nullptr)} , m_capacity{exchange(other.m_capacity, 0)} , m_size{exchange(other.m_size, 0)} - , m_allocator{ASL_MOVE(other.m_allocator)} + , m_allocator{std::move(other.m_allocator)} {} hash_set& operator=(hash_set&& other) @@ -351,7 +351,7 @@ public: m_values = exchange(other.m_values, nullptr); m_capacity = exchange(other.m_capacity, 0); m_size = exchange(other.m_size, 0); - m_allocator = ASL_MOVE(other.m_allocator); + m_allocator = std::move(other.m_allocator); } return *this; } @@ -393,7 +393,7 @@ public: { maybe_grow_to_fit_one_more(); ASL_ASSERT(m_size < max_size()); - insert_inner(ASL_MOVE(T{ASL_FWD(args)...}), m_tags, m_values, m_capacity, &m_size); + insert_inner(T{std::forward<Args>(args)...}, m_tags, m_values, m_capacity, &m_size); } template<typename U> diff --git a/asl/containers/hash_set_tests.cpp b/asl/containers/hash_set_tests.cpp index d9462d5..515fe76 100644 --- a/asl/containers/hash_set_tests.cpp +++ b/asl/containers/hash_set_tests.cpp @@ -170,7 +170,7 @@ ASL_TEST(move) set1.insert(i); } - asl::hash_set<int> set2 = ASL_MOVE(set1); + asl::hash_set<int> set2 = std::move(set1); ASL_TEST_EXPECT(set2.size() == 100); for (int i = 0; i < 100; ++i) @@ -178,7 +178,7 @@ ASL_TEST(move) ASL_TEST_EXPECT(set2.contains(i)); } - set1 = ASL_MOVE(set2); + set1 = std::move(set2); ASL_TEST_EXPECT(set1.size() == 100); for (int i = 0; i < 100; ++i) diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp index fc911ec..2af02eb 100644 --- a/asl/containers/intrusive_list.hpp +++ b/asl/containers/intrusive_list.hpp @@ -43,8 +43,8 @@ public: push_front(head); } - ASL_DELETE_COPY(IntrusiveList) - ASL_DEFAULT_MOVE(IntrusiveList) + ASL_DELETE_COPY(IntrusiveList); + ASL_DEFAULT_MOVE(IntrusiveList); ~IntrusiveList() = default; constexpr bool is_empty() const { return m_head == nullptr; } diff --git a/asl/hashing/hash.hpp b/asl/hashing/hash.hpp index d4b0910..443a774 100644 --- a/asl/hashing/hash.hpp +++ b/asl/hashing/hash.hpp @@ -89,7 +89,7 @@ struct HashState { for (const auto& value: s) { - h = AslHashValue(ASL_MOVE(h), value); + h = AslHashValue(std::move(h), value); } return h; } @@ -103,7 +103,7 @@ struct HashState template<hashable_generic<HashState> Arg, hashable_generic<HashState>... Remaining> static constexpr HashState combine(HashState h, const Arg& arg, const Remaining&... remaining) { - return combine(AslHashValue(ASL_MOVE(h), arg), remaining...); + return combine(AslHashValue(std::move(h), arg), remaining...); } }; @@ -113,13 +113,13 @@ concept hashable = hashable_generic<T, HashState>; template<typename H, uniquely_represented T> constexpr H AslHashValue(H h, const T& value) { - return H::combine_contiguous(ASL_MOVE(h), span<const T>{&value, 1}); + return H::combine_contiguous(std::move(h), span<const T>{&value, 1}); } template<typename H> constexpr H AslHashValue(H h, bool value) { - return AslHashValue(ASL_MOVE(h), value ? 1 : 0); + return AslHashValue(std::move(h), value ? 1 : 0); } template<typename H, typename T> @@ -128,7 +128,7 @@ constexpr void AslHashValue(H h, T*); // Don't hash pointers template<typename H, hashable T> constexpr H AslHashValue(H h, const span<T>& s) { - return H::combine_contiguous(ASL_MOVE(h), span<const T>{s.data(), s.size()}); + return H::combine_contiguous(std::move(h), span<const T>{s.data(), s.size()}); } template<hashable T> diff --git a/asl/logging/logging.cpp b/asl/logging/logging.cpp index edf065d..2cb9a3f 100644 --- a/asl/logging/logging.cpp +++ b/asl/logging/logging.cpp @@ -3,14 +3,22 @@ // SPDX-License-Identifier: BSD-3-Clause #include "asl/logging/logging.hpp" + +#include "asl/containers/intrusive_list.hpp" +#include "asl/formatting/format.hpp" #include "asl/io/print.hpp" +#include "asl/io/writer.hpp" #include "asl/strings/string_builder.hpp" +#include "asl/strings/string_view.hpp" +#include "asl/types/span.hpp" // @Todo Don't use internal get_stdout_writer, make console module +// NOLINTNEXTLINE(*-avoid-non-const-global-variables) static asl::log::DefaultLogger<asl::Writer*> g_default_logger{asl::print_internals::get_stdout_writer()}; // @Todo Protect the loggers list being a mutex +// NOLINTNEXTLINE(*-avoid-non-const-global-variables) static asl::IntrusiveList<asl::log::Logger> g_loggers(&g_default_logger); void asl::log::register_logger(Logger* logger) @@ -56,7 +64,7 @@ void asl::log::log_inner( StringWriter msg_writer{}; asl::format_internals::format(&msg_writer, fmt, args); - message m{ + const message m{ .level = l, .message = msg_writer.as_string_view(), .location = sl, diff --git a/asl/logging/logging.hpp b/asl/logging/logging.hpp index 9ff0d08..9c74b31 100644 --- a/asl/logging/logging.hpp +++ b/asl/logging/logging.hpp @@ -48,7 +48,11 @@ class DefaultLogger : public DefaultLoggerBase W m_writer; public: - explicit constexpr DefaultLogger(W&& writer) : m_writer{ASL_FWD(writer)} {} + template<typename U> + explicit constexpr DefaultLogger(U&& writer) + requires constructible_from<W, U&&> + : m_writer{std::forward<U>(writer)} + {} constexpr void log(const message& m) override { diff --git a/asl/logging/logging_tests.cpp b/asl/logging/logging_tests.cpp index ec47a8a..ea5bd2a 100644 --- a/asl/logging/logging_tests.cpp +++ b/asl/logging/logging_tests.cpp @@ -2,10 +2,11 @@ // // SPDX-License-Identifier: BSD-3-Clause +#include "asl/base/defer.hpp" #include "asl/logging/logging.hpp" -#include "asl/testing/testing.hpp" #include "asl/strings/string_builder.hpp" -#include "asl/base/defer.hpp" +#include "asl/strings/string_view.hpp" +#inc |