From f0cccbe3285c039553e1fd8b5a5c7830d6087974 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 6 Mar 2025 22:56:56 +0100 Subject: 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. --- asl/base/assert.cpp | 5 +++ asl/base/defer.hpp | 6 ++-- asl/base/functional.hpp | 22 ++++++------- asl/base/utility.hpp | 69 +++++++++++++++++++++++++++------------ asl/base/utility_tests.cpp | 44 ++++++++++++------------- asl/containers/buffer.hpp | 24 +++++++------- asl/containers/buffer_tests.cpp | 16 ++++----- asl/containers/hash_map.hpp | 10 +++--- asl/containers/hash_set.hpp | 12 +++---- asl/containers/hash_set_tests.cpp | 4 +-- asl/containers/intrusive_list.hpp | 4 +-- asl/hashing/hash.hpp | 10 +++--- asl/logging/logging.cpp | 10 +++++- asl/logging/logging.hpp | 6 +++- asl/logging/logging_tests.cpp | 7 ++-- asl/memory/allocator.hpp | 4 +-- asl/memory/memory.hpp | 6 ++-- asl/strings/string.hpp | 6 ++-- asl/strings/string_builder.hpp | 24 +++++++------- asl/testing/testing.cpp | 42 ++++++++++++++++-------- asl/testing/testing.hpp | 5 +-- asl/types/box.hpp | 22 ++++++------- asl/types/box_tests.cpp | 6 ++-- asl/types/maybe_uninit.hpp | 12 +++---- asl/types/option.hpp | 56 +++++++++++++++---------------- asl/types/option_tests.cpp | 12 +++---- asl/types/status.cpp | 4 +-- asl/types/status.hpp | 8 ++--- asl/types/status_or.hpp | 26 +++++++-------- asl/types/status_or_tests.cpp | 4 +-- 30 files changed, 273 insertions(+), 213 deletions(-) (limited to 'asl') 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 - explicit DeferCallback(T&& callback) : m_callback(ASL_FWD(callback)) + explicit DeferCallback(T&& callback) : m_callback(std::forward(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 DeferCallback operator<<(Callback&& callback) const { - return DeferCallback(ASL_FWD(callback)); + return DeferCallback(std::forward(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 constexpr auto invoke(is_func auto C::* f, auto&& self, Args&&... args) - -> decltype((self.*f)(ASL_FWD(args)...)) + -> decltype((self.*f)(std::forward(args)...)) requires requires { - (self.*f)(ASL_FWD(args)...); + (self.*f)(std::forward(args)...); } { - return (ASL_FWD(self).*f)(ASL_FWD(args)...); + return (std::forward(self).*f)(std::forward(args)...); } template constexpr auto invoke(is_func auto C::* f, auto* self, Args&&... args) - -> decltype((self->*f)(ASL_FWD(args)...)) + -> decltype((self->*f)(std::forward(args)...)) requires requires { - (self->*f)(ASL_FWD(args)...); + (self->*f)(std::forward(args)...); } { - return (self->*f)(ASL_FWD(args)...); + return (self->*f)(std::forward(args)...); } template @@ -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(self).*m; } template @@ -53,12 +53,12 @@ constexpr auto invoke(is_object auto C::* m, auto* self, Args&&...) template constexpr auto invoke(auto&& f, Args&&... args) - -> decltype(f(ASL_FWD(args)...)) + -> decltype(f(std::forward(args)...)) requires requires { - f(ASL_FWD(args)...); + f(std::forward(args)...); } { - return ASL_FWD(f)(ASL_FWD(args)...); + return std::forward(f)(std::forward(args)...); } template @@ -76,7 +76,7 @@ using invoke_result_t = _invoke_result_helper::type; template concept invocable = requires (F&& f, Args&&... args) { - invoke(ASL_FWD(f), ASL_FWD(args)...); + invoke(std::forward(f), std::forward(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&&>(__VA_ARGS__)) +namespace std +{ + +template +constexpr asl::un_ref_t&& move(T&& t) noexcept // NOLINT +{ + return static_cast&&>(t); +} + +template +constexpr T&& forward(asl::un_ref_t& t) noexcept // NOLINT +{ + return static_cast(t); +} + +template< class T > +constexpr T&& forward(asl::un_ref_t&& t) noexcept // NOLINT +{ + return static_cast(t); +} + +template +constexpr auto forward_like(U&& x) noexcept -> asl::copy_cref_t // NOLINT +{ + using return_type = asl::copy_cref_t; + return static_cast(x); +} -#define ASL_FWD(expr_) (static_cast(expr_)) +} // namespace std -#define ASL_FWD_LIKE(ref_, expr_) (static_cast<::asl::copy_cref_t>(expr_)) namespace asl { @@ -22,16 +47,16 @@ static constexpr in_place_t in_place{}; template 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 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(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 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(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 -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(id).get(); } ASL_TEST(forward_like) { int x{}; - ASL_TEST_EXPECT(test_fwd_like(x) == 1); + ASL_TEST_EXPECT(test_fwd_like(7) == 1); ASL_TEST_EXPECT(test_fwd_like(x) == 3); - ASL_TEST_EXPECT(test_fwd_like(ASL_MOVE(x)) == 2); - ASL_TEST_EXPECT(test_fwd_like(ASL_MOVE(x)) == 4); + ASL_TEST_EXPECT(test_fwd_like(8) == 2); + ASL_TEST_EXPECT(test_fwd_like(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(it, ASL_FWD(args)...); + construct_at(it, std::forward(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 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 - : 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 { 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* uninit = push_uninit(); - T* init = construct_at(uninit, ASL_FWD(args)...); + T* init = construct_at(uninit, std::forward(args)...); return *init; } @@ -410,12 +410,12 @@ public: return contiguous_iterator{self.data() + self.size()}; } - constexpr operator span() const // NOLINT(*-explicit-conversions) + constexpr operator span() const // NOLINT(*explicit*) { return as_span(); } - constexpr operator span() // NOLINT(*-explicit-conversions) + constexpr operator span() // 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(std::forward(self).data()[i]); } template requires hashable 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 buf2(ASL_MOVE(buf)); + asl::buffer 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 buf2(ASL_MOVE(buf)); + asl::buffer 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 buf2(ASL_MOVE(buf)); + asl::buffer 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 = default; explicit constexpr hash_map(Allocator allocator) - : Base{ASL_MOVE(allocator)} + : Base{std::move(allocator)} {} hash_map(const hash_map&) requires copyable && copyable = 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) { - 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); } 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), std::forward(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(key), V{std::forward(arg0), std::forward(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)...}, m_tags, m_values, m_capacity, &m_size); } template 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 set2 = ASL_MOVE(set1); + asl::hash_set 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 Arg, hashable_generic... 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; template constexpr H AslHashValue(H h, const T& value) { - return H::combine_contiguous(ASL_MOVE(h), span{&value, 1}); + return H::combine_contiguous(std::move(h), span{&value, 1}); } template constexpr H AslHashValue(H h, bool value) { - return AslHashValue(ASL_MOVE(h), value ? 1 : 0); + return AslHashValue(std::move(h), value ? 1 : 0); } template @@ -128,7 +128,7 @@ constexpr void AslHashValue(H h, T*); // Don't hash pointers template constexpr H AslHashValue(H h, const span& s) { - return H::combine_contiguous(ASL_MOVE(h), span{s.data(), s.size()}); + return H::combine_contiguous(std::move(h), span{s.data(), s.size()}); } template 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 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 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 + explicit constexpr DefaultLogger(U&& writer) + requires constructible_from + : m_writer{std::forward(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" +#include "asl/testing/testing.hpp" ASL_TEST(log) { @@ -27,6 +28,6 @@ ASL_TEST(custom_writer) ASL_LOG_INFO("Hello"); auto sv = string_writer.as_string_view(); - ASL_TEST_EXPECT(sv == "[ INFO ] asl/logging/logging_tests.cpp:27: Hello\n"); + ASL_TEST_EXPECT(sv == "[ INFO ] asl/logging/logging_tests.cpp:28: Hello\n"); } diff --git a/asl/memory/allocator.hpp b/asl/memory/allocator.hpp index 1628a8a..bb6b992 100644 --- a/asl/memory/allocator.hpp +++ b/asl/memory/allocator.hpp @@ -37,7 +37,7 @@ template T* alloc_new(allocator auto& a, auto&&... args) { void* ptr = a.alloc(layout::of()); - return construct_at(ptr, ASL_FWD(args)...); + return construct_at(ptr, std::forward(args)...); } template @@ -50,7 +50,7 @@ void alloc_delete(allocator auto& a, T* ptr) template constexpr T* alloc_new_default(auto&&... args) { - return alloc_new(DefaultAllocator{}, ASL_FWD(args)...); + return alloc_new(DefaultAllocator{}, std::forward(args)...); } template diff --git a/asl/memory/memory.hpp b/asl/memory/memory.hpp index bf4e125..96ab562 100644 --- a/asl/memory/memory.hpp +++ b/asl/memory/memory.hpp @@ -41,7 +41,7 @@ template constexpr T* construct_at(void* ptr, Args&&... args) requires constructible_from { - return new (ptr) T{ ASL_FWD(args)... }; + return new (ptr) T{ std::forward(args)... }; // NOLINT(*-owning-memory) } template @@ -112,7 +112,7 @@ constexpr void relocate_uninit_n(T* to, T* from, isize_t n) for (isize_t i = 0; i < n; ++i) { // NOLINTNEXTLINE(*-pointer-arithmetic) - construct_at(to + i, ASL_MOVE(from[i])); + construct_at(to + i, std::move(from[i])); } destroy_n(from, n); } @@ -131,7 +131,7 @@ constexpr void relocate_assign_n(T* to, T* from, isize_t n) for (isize_t i = 0; i < n; ++i) { // NOLINTNEXTLINE(*-pointer-arithmetic) - to[i] = ASL_MOVE(from[i]); + to[i] = std::move(from[i]); } destroy_n(from, n); } diff --git a/asl/strings/string.hpp b/asl/strings/string.hpp index c2f199f..0f70228 100644 --- a/asl/strings/string.hpp +++ b/asl/strings/string.hpp @@ -16,7 +16,7 @@ class string buffer m_buffer; explicit constexpr string(buffer&& buffer) : - m_buffer{ASL_MOVE(buffer)} + m_buffer{std::move(buffer)} {} template @@ -24,7 +24,7 @@ class string public: constexpr string() requires default_constructible = default; - explicit constexpr string(Allocator allocator) : m_buffer{ASL_MOVE(allocator)} {} + explicit constexpr string(Allocator allocator) : m_buffer{std::move(allocator)} {} // NOLINTNEXTLINE(*-explicit-conversions) constexpr string(string_view sv) @@ -33,7 +33,7 @@ public: {} constexpr string(string_view sv, Allocator allocator) - : m_buffer{sv.as_span(), ASL_MOVE(allocator)} + : m_buffer{sv.as_span(), std::move(allocator)} {} constexpr ~string() = default; diff --git a/asl/strings/string_builder.hpp b/asl/strings/string_builder.hpp index c8bb4d8..eed9e6a 100644 --- a/asl/strings/string_builder.hpp +++ b/asl/strings/string_builder.hpp @@ -20,7 +20,7 @@ class StringBuilder public: constexpr StringBuilder() requires default_constructible = default; - explicit constexpr StringBuilder(Allocator allocator) : m_buffer{ASL_MOVE(allocator)} {} + explicit constexpr StringBuilder(Allocator allocator) : m_buffer{std::move(allocator)} {} constexpr ~StringBuilder() = default; @@ -44,23 +44,23 @@ public: auto push(this auto&& self, string_view sv) -> decltype(self) requires (!is_const>) { - isize_t old_size = self.m_buffer.size(); + const isize_t old_size = self.m_buffer.size(); self.m_buffer.resize_zero(old_size + sv.size()); // NOLINTNEXTLINE(*-pointer-arithmetic) asl::memcpy(self.m_buffer.data() + old_size, sv.data(), sv.size()); - return ASL_FWD(self); + return std::forward(self); } auto push(this auto&& self, char c) -> decltype(self) requires (!is_const>) { self.m_buffer.push(c); - return ASL_FWD(self); + return std::forward(self); } string finish() && { - return string{ASL_MOVE(m_buffer)}; + return string{std::move(m_buffer)}; } template @@ -73,7 +73,7 @@ public: template string as_string(Allocator allocator) const { - return string{as_string_view(), ASL_MOVE(allocator)}; + return string{as_string_view(), std::move(allocator)}; } }; @@ -86,7 +86,7 @@ class StringWriter : public asl::Writer public: constexpr StringWriter() requires default_constructible = default; - explicit constexpr StringWriter(Allocator allocator) : m_builder{ASL_MOVE(allocator)} {} + explicit constexpr StringWriter(Allocator allocator) : m_builder{std::move(allocator)} {} constexpr ~StringWriter() override = default; @@ -108,7 +108,7 @@ public: string finish() && { - return ASL_MOVE(m_builder).finish(); + return std::move(m_builder).finish(); } template @@ -121,7 +121,7 @@ public: template string as_string(Allocator allocator) const { - return m_builder.as_string(ASL_MOVE(allocator)); + return m_builder.as_string(std::move(allocator)); } }; @@ -133,15 +133,15 @@ string format_to_string(string_view fmt, const formattable auto&... a { StringWriter writer{}; format(&writer, fmt, args...); - return ASL_MOVE(writer).finish(); + return std::move(writer).finish(); } template string format_to_string(Allocator allocator, string_view fmt, const formattable auto&... args) { - StringWriter writer{ASL_MOVE(allocator)}; + StringWriter writer{std::move(allocator)}; format(&writer, fmt, args...); - return ASL_MOVE(writer).finish(); + return std::move(writer).finish(); } } // namespace asl diff --git a/asl/testing/testing.cpp b/asl/testing/testing.cpp index 4e62002..53e2bb0 100644 --- a/asl/testing/testing.cpp +++ b/asl/testing/testing.cpp @@ -4,37 +4,51 @@ #include "asl/testing/testing.hpp" +#include "asl/base/assert.hpp" +#include "asl/base/meta.hpp" +#include "asl/base/utility.hpp" #include "asl/io/print.hpp" -static asl::testing::Test* g_head = nullptr; -static asl::testing::Test* g_tail = nullptr; +namespace +{ + +struct TestingState +{ + asl::testing::Test* head = nullptr; + asl::testing::Test* tail = nullptr; + + bool current_test_fail = false; +}; + +} // namespace + +// NOLINTNEXTLINE(*-avoid-non-const-global-variables) +static TestingState g_state{}; void asl::testing::register_test(Test* test) { - if (g_head == nullptr && g_tail == nullptr) + if (g_state.head == nullptr && g_state.tail == nullptr) { - g_head = test; - g_tail = test; + g_state.head = test; + g_state.tail = test; } else { - g_tail->m_next = test; - test->m_prev = asl::exchange(g_tail, test); + g_state.tail->m_next = test; + test->m_prev = asl::exchange(g_state.tail, test); } } -static bool g_current_test_fail = false; - void asl::testing::report_failure(const char* msg, const asl::source_location& sl) { asl::eprint("--------------------------------------------------------------\n"); asl::eprint("Test assertion failed at {}, line {}:\n", sl.file, sl.line); asl::eprint(" {}\n", msg); asl::eprint("--------------------------------------------------------------\n"); - g_current_test_fail = true; + g_state.current_test_fail = true; } -static void report_assert_failure(const char* msg, const asl::source_location& sl, void*) +static void report_assert_failure(const char* msg, const asl::source_location& sl, void* /* userdata */) { asl::eprint("------------------------------------------------------------\n"); asl::eprint("Assertion failure at {}, line {}:\n", sl.file, sl.line); @@ -55,14 +69,14 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) asl::testing::Test* failed_head = nullptr; - for (auto* it = g_head; it != nullptr; it = it->m_next) + for (auto* it = g_state.head; it != nullptr; it = it->m_next) { asl::eprint(GREEN("[ RUN ]") " {}\n", it->m_case_name); - g_current_test_fail = false; + g_state.current_test_fail = false; it->m_fn(); - if (!g_current_test_fail) + if (!g_state.current_test_fail) { asl::eprint(GREEN("[ OK ]") " {}\n", it->m_case_name); pass += 1; diff --git a/asl/testing/testing.hpp b/asl/testing/testing.hpp index 849c4fd..3b4a421 100644 --- a/asl/testing/testing.hpp +++ b/asl/testing/testing.hpp @@ -4,7 +4,7 @@ #pragma once -#include "asl/base/utility.hpp" +#include "asl/base/meta.hpp" namespace asl::testing { @@ -35,7 +35,8 @@ struct Test } // namespace asl::testing #define ASL_TEST(CASE) \ - static void asl_test_fn_##CASE(); \ + static void asl_test_fn_##CASE(); /* NOLINT */ \ + /* NOLINTNEXTLINE */ \ static ::asl::testing::Test asl_test_##CASE( \ #CASE, \ asl_test_fn_##CASE); \ diff --git a/asl/types/box.hpp b/asl/types/box.hpp index 4b6e0b3..6501e3e 100644 --- a/asl/types/box.hpp +++ b/asl/types/box.hpp @@ -29,21 +29,21 @@ public: constexpr box(T* ptr, Allocator alloc) : m_ptr{ptr} - , m_alloc{ASL_MOVE(alloc)} + , m_alloc{std::move(alloc)} { ASL_ASSERT(m_ptr != nullptr); } constexpr box(box&& other) : m_ptr{exchange(other.m_ptr, nullptr)} - , m_alloc{ASL_MOVE(other.m_alloc)} + , m_alloc{std::move(other.m_alloc)} {} template requires convertible_from - constexpr box(box&& other) // NOLINT(*-explicit-conversions) + constexpr box(box&& other) // NOLINT(*explicit*,*-not-moved) : m_ptr{exchange(other.m_ptr, nullptr)} - , m_alloc{ASL_MOVE(other.m_alloc)} + , m_alloc{std::move(other.m_alloc)} {} constexpr box& operator=(box&& other) @@ -53,7 +53,7 @@ public: if (m_ptr != nullptr) { reset(); } m_ptr = exchange(other.m_ptr, nullptr); - m_alloc = ASL_MOVE(other.m_alloc); + m_alloc = std::move(other.m_alloc); return *this; } @@ -99,7 +99,7 @@ public: requires hashable friend H AslHashValue(H h, const box& b) { - return H::combine(ASL_MOVE(h), *b); + return H::combine(std::move(h), *b); } template @@ -114,8 +114,8 @@ constexpr box make_box_in(Allocator allocator, Args&&... args) requires constructible_from { void* raw_ptr = allocator.alloc(layout::of()); - auto* ptr = construct_at(raw_ptr, ASL_FWD(args)...); - return box(ptr, ASL_MOVE(allocator)); + auto* ptr = construct_at(raw_ptr, std::forward(args)...); + return box(ptr, std::move(allocator)); } template @@ -124,14 +124,14 @@ constexpr box make_box(Args&&... args) { Allocator allocator{}; void* raw_ptr = allocator.alloc(layout::of()); - auto* ptr = construct_at(raw_ptr, ASL_FWD(args)...); - return box(ptr, ASL_MOVE(allocator)); + auto* ptr = construct_at(raw_ptr, std::forward(args)...); + return box(ptr, std::move(allocator)); } template constexpr T* leak(box&& b) { - return exchange(b.m_ptr, nullptr); + return exchange(std::move(b).m_ptr, nullptr); } } // namespace asl diff --git a/asl/types/box_tests.cpp b/asl/types/box_tests.cpp index 210943c..d7281ed 100644 --- a/asl/types/box_tests.cpp +++ b/asl/types/box_tests.cpp @@ -23,7 +23,7 @@ ASL_TEST(destructor) ASL_TEST_ASSERT(!d); - auto box3 = ASL_MOVE(box); + auto box3 = std::move(box); ASL_TEST_ASSERT(!d); } @@ -35,7 +35,7 @@ ASL_TEST(value) auto b = asl::make_box(24); ASL_TEST_EXPECT(*b == 24); - auto b2 = ASL_MOVE(b); + auto b2 = std::move(b); ASL_TEST_EXPECT(*b2 == 24); } @@ -44,7 +44,7 @@ ASL_TEST(ptr) auto b = asl::make_box(24); auto* ptr1 = b.get(); - auto b2 = ASL_MOVE(b); + auto b2 = std::move(b); auto* ptr2 = b2.get(); ASL_TEST_EXPECT(ptr1 == ptr2); } diff --git a/asl/types/maybe_uninit.hpp b/asl/types/maybe_uninit.hpp index a0d6b86..3b2f755 100644 --- a/asl/types/maybe_uninit.hpp +++ b/asl/types/maybe_uninit.hpp @@ -23,7 +23,7 @@ public: explicit constexpr maybe_uninit(in_place_t, auto&&... args) requires constructible_from - : m_value{ASL_FWD(args)...} + : m_value{std::forward(args)...} {} constexpr maybe_uninit(const maybe_uninit&) requires trivially_copy_constructible = default; @@ -33,10 +33,10 @@ public: constexpr maybe_uninit(maybe_uninit&&) requires (!trivially_move_constructible) {} // NOLINT constexpr maybe_uninit& operator=(const maybe_uninit&) requires trivially_copy_assignable = default; - constexpr maybe_uninit& operator=(const maybe_uninit&) requires (!trivially_copy_assignable) {} + constexpr maybe_uninit& operator=(const maybe_uninit&) requires (!trivially_copy_assignable) { return *this; } // NOLINT constexpr maybe_uninit& operator=(maybe_uninit&&) requires trivially_move_assignable = default; - constexpr maybe_uninit& operator=(maybe_uninit&&) requires (!trivially_move_assignable) {} + constexpr maybe_uninit& operator=(maybe_uninit&&) requires (!trivially_move_assignable) { return *this; } // NOLINT constexpr ~maybe_uninit() requires trivially_destructible = default; constexpr ~maybe_uninit() requires (!trivially_destructible) {} // NOLINT @@ -45,14 +45,14 @@ public: constexpr void construct_unsafe(auto&&... args) requires constructible_from { - construct_at(&m_value, ASL_FWD(args)...); + construct_at(&m_value, std::forward(args)...); } // @Safety Value must have been initialized constexpr void assign_unsafe(auto&& value) requires assignable_from { - m_value = ASL_FWD(value); + m_value = std::forward(value); } // @Safety Value must have been initialized @@ -67,7 +67,7 @@ public: // @Safety Value must have been initialized constexpr auto&& as_init_unsafe(this auto&& self) { - return ASL_FWD(self).m_value; + return std::forward(self).m_value; } }; diff --git a/asl/types/option.hpp b/asl/types/option.hpp index c25d12d..9c317b0 100644 --- a/asl/types/option.hpp +++ b/asl/types/option.hpp @@ -74,19 +74,19 @@ class option if constexpr (!kHasNiche) { - m_payload.construct_unsafe(ASL_FWD(args)...); + m_payload.construct_unsafe(std::forward(args)...); m_has_value = true; } else { if constexpr (move_assignable) { - m_payload.assign_unsafe(ASL_MOVE(T{ASL_FWD(args)...})); + m_payload.assign_unsafe(T{std::forward(args)...}); } else { m_payload.destroy_unsafe(); - m_payload.construct_unsafe(ASL_FWD(args)...); + m_payload.construct_unsafe(std::forward(args)...); } } } @@ -95,7 +95,7 @@ class option constexpr void assign(U&& arg) { ASL_ASSERT(has_value()); - m_payload.assign_unsafe(ASL_FWD(arg)); + m_payload.assign_unsafe(std::forward(arg)); } public: @@ -103,10 +103,10 @@ public: constexpr option() : option{nullopt} {} - // NOLINTNEXTLINE(*-explicit-conversions) + // NOLINTNEXTLINE(*explicit*) constexpr option(nullopt_t) requires (!kHasNiche) {} - // NOLINTNEXTLINE(*-explicit-conversions) + // NOLINTNEXTLINE(*explicit*) constexpr option(nullopt_t) requires kHasNiche : m_payload{in_place, niche_t{}} {} template @@ -117,7 +117,7 @@ public: constructible_from && !same_as, option> ) - : m_payload{in_place, ASL_FWD(value)} + : m_payload{in_place, std::forward(value)} {} template @@ -128,7 +128,7 @@ public: constructible_from && !is_option ) - : m_payload{in_place, ASL_FWD(value)} + : m_payload{in_place, std::forward(value)} , m_has_value{true} {} @@ -154,7 +154,7 @@ public: { if (other.has_value()) { - construct(ASL_MOVE(other.m_payload.as_init_unsafe())); + construct(std::move(other.m_payload.as_init_unsafe())); } } @@ -184,7 +184,7 @@ public: { if (other.has_value()) { - construct(ASL_MOVE(other.m_payload.as_init_unsafe())); + construct(std::move(other).m_payload.as_init_unsafe()); } } @@ -204,11 +204,11 @@ public: { if (has_value()) { - assign(ASL_FWD(value)); + assign(std::forward(value)); } else { - construct(ASL_FWD(value)); + construct(std::forward(value)); } return *this; @@ -259,11 +259,11 @@ public: { if (has_value()) { - assign(ASL_MOVE(other.m_payload.as_init_unsafe())); + assign(std::move(other.m_payload.as_init_unsafe())); } else { - construct(ASL_MOVE(other.m_payload.as_init_unsafe())); + construct(std::move(other.m_payload.as_init_unsafe())); } } else if (has_value()) @@ -313,11 +313,11 @@ public: { if (has_value()) { - assign(ASL_MOVE(other.m_payload.as_init_unsafe())); + assign(std::move(other).m_payload.as_init_unsafe()); } else { - construct(ASL_MOVE(other.m_payload.as_init_unsafe())); + construct(std::move(other).m_payload.as_init_unsafe()); } } else if (has_value()) @@ -342,7 +342,7 @@ public: { if constexpr (move_assignable) { - m_payload.assign_unsafe(ASL_MOVE(T{niche_t{}})); + m_payload.assign_unsafe(std::move(T{niche_t{}})); } else { @@ -357,7 +357,7 @@ public: } } - constexpr bool has_value() const + [[nodiscard]] constexpr bool has_value() const { if constexpr (kHasNiche) { @@ -372,28 +372,28 @@ public: constexpr auto&& value(this auto&& self) { ASL_ASSERT_RELEASE(self.has_value()); - return ASL_FWD(self).m_payload.as_init_unsafe(); + return std::forward(self).m_payload.as_init_unsafe(); } template constexpr T value_or(U&& other_value) const& requires copy_constructible && convertible_from { - return has_value() ? value() : static_cast(ASL_FWD(other_value)); + return has_value() ? value() : static_cast(std::forward(other_value)); } template constexpr T value_or(U&& other_value) && requires move_constructible && convertible_from { - return has_value() ? ASL_MOVE(value()) : static_cast(ASL_FWD(other_value)); + return has_value() ? std::move(value()) : static_cast(std::forward(other_value)); } constexpr T& emplace(auto&&... args) & requires constructible_from { if (has_value()) { reset(); } - construct(ASL_FWD(args)...); + construct(std::forward(args)...); return value(); } @@ -405,7 +405,7 @@ public: if (self.has_value()) { - return invoke(ASL_FWD(f), ASL_FWD(self).value()); + return invoke(std::forward(f), std::forward(self).value()); } return Result{ asl::nullopt }; } @@ -417,7 +417,7 @@ public: if (self.has_value()) { return option>{ - invoke(ASL_FWD(f), ASL_FWD(self).value()) + invoke(std::forward(f), std::forward(self).value()) }; } return option>{ asl::nullopt }; @@ -427,14 +427,14 @@ public: constexpr option or_else(F&& f) const& requires same_as>, option> { - return has_value() ? *this : invoke(ASL_FWD(f)); + return has_value() ? *this : invoke(std::forward(f)); } template constexpr option or_else(F&& f) && requires same_as>, option> { - return has_value() ? ASL_MOVE(*this) : invoke(ASL_FWD(f)); + return has_value() ? std::move(*this) : invoke(std::forward(f)); } template @@ -443,9 +443,9 @@ public: { if (!opt.has_value()) { - return H::combine(ASL_MOVE(h), 0); + return H::combine(std::move(h), 0); } - return H::combine(ASL_MOVE(h), 1, opt.value()); + return H::combine(std::move(h), 1, opt.value()); } }; diff --git a/asl/types/option_tests.cpp b/asl/types/option_tests.cpp index 22b34d3..2dff6f5 100644 --- a/asl/types/option_tests.cpp +++ b/asl/types/option_tests.cpp @@ -129,10 +129,10 @@ ASL_TEST(call_destructor) { DestructorObserver obs(&destroyed); - asl::option opt(ASL_MOVE(obs)); + asl::option opt(std::move(obs)); ASL_TEST_EXPECT(!destroyed); - asl::option opt2 = ASL_MOVE(opt); + asl::option opt2 = std::move(opt); ASL_TEST_EXPECT(!destroyed); } @@ -172,7 +172,7 @@ ASL_TEST(value_move) ASL_TEST_EXPECT(!destroyed); { - auto x = ASL_MOVE(opt).value(); + auto x = std::move(opt).value(); ASL_TEST_EXPECT(!destroyed); } @@ -208,19 +208,19 @@ ASL_TEST(convert_copy) ASL_TEST(convert_move) { asl::option opt8 = uint8_t{8}; - asl::option opt16 = ASL_MOVE(opt8); + asl::option opt16 = std::move(opt8); ASL_TEST_ASSERT(opt16.has_value()); ASL_TEST_EXPECT(opt16.value() == 8); - opt8 = ASL_MOVE(uint8_t{10}); + opt8 = std::move(uint8_t{10}); ASL_TEST_ASSERT(opt8.has_value()); ASL_TEST_EXPECT(opt8.value() == 10); opt16 = asl::nullopt; ASL_TEST_EXPECT(!opt16.has_value()); - opt16 = ASL_MOVE(opt8); + opt16 = std::move(opt8); ASL_TEST_ASSERT(opt16.has_value()); ASL_TEST_EXPECT(opt16.value() == 10); } diff --git a/asl/types/status.cpp b/asl/types/status.cpp index fd751d1..94c4977 100644 --- a/asl/types/status.cpp +++ b/asl/types/status.cpp @@ -23,7 +23,7 @@ struct StatusInternal asl::atomic ref_count; constexpr StatusInternal(asl::string&& msg_, asl::status_code code_) - : msg{ASL_MOVE(msg_)} + : msg{std::move(msg_)} , code{code_} { ASL_ASSERT(code != asl::status_code::ok); @@ -41,7 +41,7 @@ asl::status::status(status_code code, string_view fmt, span sink{g_allocator}; format_internals::format(&sink, fmt, args); - m_payload = alloc_new(g_allocator, ASL_MOVE(sink).finish(), code); + m_payload = alloc_new(g_allocator, std::move(sink).finish(), code); } asl::status_code asl::status::code_internal() const diff --git a/asl/types/status.hpp b/asl/types/status.hpp index 31b6df6..83be5ce 100644 --- a/asl/types/status.hpp +++ b/asl/types/status.hpp @@ -122,7 +122,7 @@ public: return {}; } - constexpr status&& throw_status() && { return ASL_MOVE(*this); } + constexpr status&& throw_status() && { return std::move(*this); } friend void AslFormat(Formatter& f, const status&); @@ -131,9 +131,9 @@ public: { if (s.is_inline()) { - return H::combine(ASL_MOVE(h), s.code()); + return H::combine(std::move(h), s.code()); } - return H::combine(ASL_MOVE(h), s.code(), s.message()); + return H::combine(std::move(h), s.code(), s.message()); } }; @@ -156,6 +156,6 @@ ASL_DEFINE_ERROR_(internal) ASL_DEFINE_ERROR_(runtime) ASL_DEFINE_ERROR_(invalid_argument) -#define ASL_TRY(VALUE) if (VALUE.ok()) {} else { return ASL_MOVE(VALUE).throw_status(); } +#define ASL_TRY(VALUE) if (VALUE.ok()) {} else { return std::move(VALUE).throw_status(); } } // namespace asl diff --git a/asl/types/status_or.hpp b/asl/types/status_or.hpp index c40ecce..be6bb06 100644 --- a/asl/types/status_or.hpp +++ b/asl/types/status_or.hpp @@ -33,11 +33,11 @@ public: constexpr status_or(status_or&& other) requires move_constructible - : m_status{ASL_MOVE(other.m_status)} + : m_status{std::move(other.m_status)} { if (other.ok()) { - m_value.construct_unsafe(ASL_MOVE(other.m_value.as_init_unsafe())); + m_value.construct_unsafe(std::move(other.m_value.as_init_unsafe())); } } @@ -75,7 +75,7 @@ public: { if (other.ok()) { - m_value.assign_unsafe(ASL_MOVE(other.m_value.as_init_unsafe())); + m_value.assign_unsafe(std::move(other.m_value.as_init_unsafe())); } else { @@ -84,9 +84,9 @@ public: } else if (other.ok()) { - m_value.construct_unsafe(ASL_MOVE(other.m_value.as_init_unsafe())); + m_value.construct_unsafe(std::move(other.m_value.as_init_unsafe())); } - m_status = ASL_MOVE(other.m_status); + m_status = std::move(other.m_status); } return *this; } @@ -106,7 +106,7 @@ public: } // NOLINTNEXTLINE(*-explicit-conversions) - constexpr status_or(status&& status) : m_status{ASL_MOVE(status)} + constexpr status_or(status&& status) : m_status{std::move(status)} { ASL_ASSERT_RELEASE(!m_status.ok()); } @@ -122,7 +122,7 @@ public: !same_as, status> ) : m_status{status_code::ok} - , m_value{in_place, ASL_FWD(value)} + , m_value{in_place, std::forward(value)} {} constexpr bool ok() const { return m_status.ok(); } @@ -131,26 +131,26 @@ public: constexpr string_view message() const { return m_status.message(); } - constexpr status&& throw_status() && { return ASL_MOVE(m_status); } + constexpr status&& throw_status() && { return std::move(m_status); } constexpr auto&& value(this auto&& self) { ASL_ASSERT_RELEASE(self.ok()); - return ASL_FWD(self).m_value.as_init_unsafe(); + return std::forward(self).m_value.as_init_unsafe(); } template constexpr T value_or(U&& other_value) const& requires copy_constructible && convertible_from { - return ok() ? value() : static_cast(ASL_FWD(other_value)); + return ok() ? value() : static_cast(std::forward(other_value)); } template constexpr T value_or(U&& other_value) && requires move_constructible && convertible_from { - return ok() ? ASL_MOVE(value()) : static_cast(ASL_FWD(other_value)); + return ok() ? std::move(value()) : static_cast(std::forward(other_value)); } friend void AslFormat(Formatter& f, const status_or& status) @@ -164,9 +164,9 @@ public: { if (s.ok()) { - return H::combine(ASL_MOVE(h), s.m_status, s.value()); + return H::combine(std::move(h), s.m_status, s.value()); } - return H::combine(ASL_MOVE(h), s.m_status); + return H::combine(std::move(h), s.m_status); } }; diff --git a/asl/types/status_or_tests.cpp b/asl/types/status_or_tests.cpp index 464b8bb..08b4a0f 100644 --- a/asl/types/status_or_tests.cpp +++ b/asl/types/status_or_tests.cpp @@ -52,11 +52,11 @@ ASL_TEST(destructor) ASL_TEST_EXPECT(s.ok()); ASL_TEST_EXPECT(!d); - asl::status_or s2 = ASL_MOVE(s); + asl::status_or s2 = std::move(s); ASL_TEST_EXPECT(s.ok()); ASL_TEST_EXPECT(!d); - s = ASL_MOVE(s2); + s = std::move(s2); ASL_TEST_EXPECT(s.ok()); ASL_TEST_EXPECT(!d); } -- cgit