summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-26 00:40:51 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-26 00:42:44 +0100
commitcf7db48c261ee9c896c813a38ff8c59da5b8fe07 (patch)
tree41d827be5db5f3322d745215fe38a9c395a52fa3 /asl
parent79aaec3d7d12bc1a0483f19eadeda325a2d65920 (diff)
Fix line endings
Diffstat (limited to 'asl')
-rw-r--r--asl/BUILD.bazel156
-rw-r--r--asl/allocator.cpp112
-rw-r--r--asl/allocator.hpp116
-rw-r--r--asl/annotations.hpp18
-rw-r--r--asl/assert.hpp66
-rw-r--r--asl/box.hpp230
-rw-r--r--asl/buffer.hpp918
-rw-r--r--asl/config.hpp34
-rw-r--r--asl/float.hpp34
-rw-r--r--asl/format.cpp402
-rw-r--r--asl/format.hpp216
-rw-r--r--asl/format_float.cpp196
-rw-r--r--asl/functional.hpp130
-rw-r--r--asl/hash.hpp276
-rw-r--r--asl/hash_cityhash.cpp1034
-rw-r--r--asl/hash_map.hpp356
-rw-r--r--asl/hash_set.hpp836
-rw-r--r--asl/integers.hpp80
-rw-r--r--asl/io.hpp38
-rw-r--r--asl/layout.hpp74
-rw-r--r--asl/log/BUILD.bazel52
-rw-r--r--asl/maybe_uninit.hpp144
-rw-r--r--asl/memory.hpp274
-rw-r--r--asl/meta.hpp442
-rw-r--r--asl/option.hpp1016
-rw-r--r--asl/print.cpp62
-rw-r--r--asl/print.hpp58
-rw-r--r--asl/span.hpp6
-rw-r--r--asl/status.cpp2
-rw-r--r--asl/status.hpp4
-rw-r--r--asl/status_or.hpp358
-rw-r--r--asl/string.hpp2
-rw-r--r--asl/string_builder.hpp2
-rw-r--r--asl/string_view.hpp2
-rw-r--r--asl/testing/BUILD.bazel26
-rw-r--r--asl/testing/testing.cpp162
-rw-r--r--asl/testing/testing.hpp92
-rw-r--r--asl/tests/box_tests.cpp156
-rw-r--r--asl/tests/buffer_tests.cpp1206
-rw-r--r--asl/tests/float_tests.cpp46
-rw-r--r--asl/tests/format_tests.cpp220
-rw-r--r--asl/tests/functional_tests.cpp146
-rw-r--r--asl/tests/hash_map_tests.cpp96
-rw-r--r--asl/tests/hash_set_tests.cpp370
-rw-r--r--asl/tests/hash_tests.cpp520
-rw-r--r--asl/tests/integers_tests.cpp30
-rw-r--r--asl/tests/maybe_uninit_tests.cpp44
-rw-r--r--asl/tests/meta_tests.cpp498
-rw-r--r--asl/tests/option_tests.cpp658
-rw-r--r--asl/tests/status_or_tests.cpp168
-rw-r--r--asl/tests/status_tests.cpp4
-rw-r--r--asl/tests/string_view_tests.cpp8
-rw-r--r--asl/tests/test_types.hpp182
-rw-r--r--asl/tests/utility_tests.cpp2
-rw-r--r--asl/utility.hpp168
55 files changed, 6274 insertions, 6274 deletions
diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel
index 2d82f4b..2cc4af5 100644
--- a/asl/BUILD.bazel
+++ b/asl/BUILD.bazel
@@ -1,78 +1,78 @@
-cc_library(
- name = "asl",
- hdrs = [
- "allocator.hpp",
- "annotations.hpp",
- "assert.hpp",
- "atomic.hpp",
- "box.hpp",
- "buffer.hpp",
- "config.hpp",
- "float.hpp",
- "format.hpp",
- "functional.hpp",
- "hash.hpp",
- "hash_map.hpp",
- "hash_set.hpp",
- "integers.hpp",
- "io.hpp",
- "layout.hpp",
- "maybe_uninit.hpp",
- "memory.hpp",
- "meta.hpp",
- "option.hpp",
- "print.hpp",
- "span.hpp",
- "status.hpp",
- "status_or.hpp",
- "string.hpp",
- "string_builder.hpp",
- "string_view.hpp",
- "utility.hpp",
- ],
- srcs = [
- "allocator.cpp",
- "assert.cpp",
- "format.cpp",
- "format_float.cpp",
- "hash_cityhash.cpp",
- "print.cpp",
- "status.cpp",
- ],
- deps = [
- "//vendor/dragonbox",
- ],
- visibility = ["//visibility:public"],
-)
-
-[cc_test(
- name = "%s_tests" % name,
- srcs = [
- "tests/%s_tests.cpp" % name,
- "tests/test_types.hpp",
- ],
- deps = [
- ":asl",
- "//asl/testing",
- ],
-) for name in [
- "box",
- "buffer",
- "float",
- "format",
- "functional",
- "hash",
- "hash_map",
- "hash_set",
- "integers",
- "maybe_uninit",
- "meta",
- "option",
- "span",
- "status",
- "status_or",
- "string",
- "string_builder",
- "string_view",
- "utility",
-]]
+cc_library(
+ name = "asl",
+ hdrs = [
+ "allocator.hpp",
+ "annotations.hpp",
+ "assert.hpp",
+ "atomic.hpp",
+ "box.hpp",
+ "buffer.hpp",
+ "config.hpp",
+ "float.hpp",
+ "format.hpp",
+ "functional.hpp",
+ "hash.hpp",
+ "hash_map.hpp",
+ "hash_set.hpp",
+ "integers.hpp",
+ "io.hpp",
+ "layout.hpp",
+ "maybe_uninit.hpp",
+ "memory.hpp",
+ "meta.hpp",
+ "option.hpp",
+ "print.hpp",
+ "span.hpp",
+ "status.hpp",
+ "status_or.hpp",
+ "string.hpp",
+ "string_builder.hpp",
+ "string_view.hpp",
+ "utility.hpp",
+ ],
+ srcs = [
+ "allocator.cpp",
+ "assert.cpp",
+ "format.cpp",
+ "format_float.cpp",
+ "hash_cityhash.cpp",
+ "print.cpp",
+ "status.cpp",
+ ],
+ deps = [
+ "//vendor/dragonbox",
+ ],
+ visibility = ["//visibility:public"],
+)
+
+[cc_test(
+ name = "%s_tests" % name,
+ srcs = [
+ "tests/%s_tests.cpp" % name,
+ "tests/test_types.hpp",
+ ],
+ deps = [
+ ":asl",
+ "//asl/testing",
+ ],
+) for name in [
+ "box",
+ "buffer",
+ "float",
+ "format",
+ "functional",
+ "hash",
+ "hash_map",
+ "hash_set",
+ "integers",
+ "maybe_uninit",
+ "meta",
+ "option",
+ "span",
+ "status",
+ "status_or",
+ "string",
+ "string_builder",
+ "string_view",
+ "utility",
+]]
diff --git a/asl/allocator.cpp b/asl/allocator.cpp
index 5dbdce0..59bff76 100644
--- a/asl/allocator.cpp
+++ b/asl/allocator.cpp
@@ -1,56 +1,56 @@
-#include "asl/allocator.hpp"
-#include "asl/assert.hpp"
-#include "asl/utility.hpp"
-#include "asl/memory.hpp"
-#include "asl/print.hpp"
-
-#include <cstdlib>
-
-// @Todo zalloc
-// @Todo Cookies
-// @Todo Debug values
-
-void* asl::GlobalHeap::alloc(const layout& layout)
-{
-#if ASL_OS_WINDOWS
- void* ptr = ::_aligned_malloc(
- static_cast<size_t>(layout.size),
- static_cast<size_t>(layout.align));
-#elif ASL_OS_LINUX
- void* ptr = ::aligned_alloc(
- static_cast<size_t>(layout.align),
- static_cast<size_t>(layout.size));
-#endif
- ASL_ASSERT(ptr != nullptr); // @Todo panic
- return ptr;
-}
-
-void* asl::GlobalHeap::realloc(void* old_ptr, [[maybe_unused]] const layout& old_layout, const layout& new_layout)
-{
-#if ASL_OS_WINDOWS
- return ::_aligned_realloc(old_ptr,
- static_cast<size_t>(new_layout.size),
- static_cast<size_t>(new_layout.align));
-#elif ASL_OS_LINUX
- if (new_layout.align <= old_layout.align)
- {
- void* new_ptr = ::realloc(old_ptr, static_cast<size_t>(new_layout.size));
- ASL_ASSERT(new_ptr != nullptr); // @Todo panic
- return new_ptr;
- }
-
- void* new_ptr = alloc(new_layout);
- asl::memcpy(new_ptr, old_ptr, asl::min(old_layout.size, new_layout.size));
- dealloc(old_ptr, old_layout);
- return new_ptr;
-#endif
-}
-
-void asl::GlobalHeap::dealloc(void* ptr, const layout&)
-{
-#if ASL_OS_WINDOWS
- ::_aligned_free(ptr);
-#elif ASL_OS_LINUX
- ::free(ptr);
-#endif
-}
+#include "asl/allocator.hpp"
+#include "asl/assert.hpp"
+#include "asl/utility.hpp"
+#include "asl/memory.hpp"
+#include "asl/print.hpp"
+
+#include <cstdlib>
+
+// @Todo zalloc
+// @Todo Cookies
+// @Todo Debug values
+
+void* asl::GlobalHeap::alloc(const layout& layout)
+{
+#if ASL_OS_WINDOWS
+ void* ptr = ::_aligned_malloc(
+ static_cast<size_t>(layout.size),
+ static_cast<size_t>(layout.align));
+#elif ASL_OS_LINUX
+ void* ptr = ::aligned_alloc(
+ static_cast<size_t>(layout.align),
+ static_cast<size_t>(layout.size));
+#endif
+ ASL_ASSERT(ptr != nullptr); // @Todo panic
+ return ptr;
+}
+
+void* asl::GlobalHeap::realloc(void* old_ptr, [[maybe_unused]] const layout& old_layout, const layout& new_layout)
+{
+#if ASL_OS_WINDOWS
+ return ::_aligned_realloc(old_ptr,
+ static_cast<size_t>(new_layout.size),
+ static_cast<size_t>(new_layout.align));
+#elif ASL_OS_LINUX
+ if (new_layout.align <= old_layout.align)
+ {
+ void* new_ptr = ::realloc(old_ptr, static_cast<size_t>(new_layout.size));
+ ASL_ASSERT(new_ptr != nullptr); // @Todo panic
+ return new_ptr;
+ }
+
+ void* new_ptr = alloc(new_layout);
+ asl::memcpy(new_ptr, old_ptr, asl::min(old_layout.size, new_layout.size));
+ dealloc(old_ptr, old_layout);
+ return new_ptr;
+#endif
+}
+
+void asl::GlobalHeap::dealloc(void* ptr, const layout&)
+{
+#if ASL_OS_WINDOWS
+ ::_aligned_free(ptr);
+#elif ASL_OS_LINUX
+ ::free(ptr);
+#endif
+}
diff --git a/asl/allocator.hpp b/asl/allocator.hpp
index 265378b..90793dd 100644
--- a/asl/allocator.hpp
+++ b/asl/allocator.hpp
@@ -1,58 +1,58 @@
-#pragma once
-
-#include "asl/layout.hpp"
-#include "asl/meta.hpp"
-#include "asl/memory.hpp"
-
-namespace asl
-{
-
-template<typename T>
-concept allocator = moveable<T> && equality_comparable<T> &&
- requires(T& alloc, layout layout, void* ptr)
- {
- { alloc.alloc(layout) } -> same_as<void*>;
- { alloc.realloc(ptr, layout, layout) } -> same_as<void*>;
- alloc.dealloc(ptr, layout);
- };
-
-class GlobalHeap
-{
-public:
- static void* alloc(const layout&);
- static void* realloc(void* ptr, const layout& old, const layout& new_layout);
- static void dealloc(void* ptr, const layout&);
-
- constexpr bool operator==(const GlobalHeap&) const { return true; }
-};
-static_assert(allocator<GlobalHeap>);
-
-using DefaultAllocator = GlobalHeap;
-
-template<typename T>
-T* alloc_new(allocator auto& a, auto&&... args)
-{
- void* ptr = a.alloc(layout::of<T>());
- return construct_at<T>(ptr, ASL_FWD(args)...);
-}
-
-template<typename T>
-void alloc_delete(allocator auto& a, T* ptr)
-{
- destroy(ptr);
- a.dealloc(ptr, layout::of<T>());
-}
-
-template<typename T>
-constexpr T* alloc_new_default(auto&&... args)
-{
- return alloc_new<T>(DefaultAllocator{}, ASL_FWD(args)...);
-}
-
-template<typename T>
-void alloc_delete_default(T* ptr)
-{
- alloc_delete(DefaultAllocator{}, ptr);
-}
-
-} // namespace asl
+#pragma once
+
+#include "asl/layout.hpp"
+#include "asl/meta.hpp"
+#include "asl/memory.hpp"
+
+namespace asl
+{
+
+template<typename T>
+concept allocator = moveable<T> && equality_comparable<T> &&
+ requires(T& alloc, layout layout, void* ptr)
+ {
+ { alloc.alloc(layout) } -> same_as<void*>;
+ { alloc.realloc(ptr, layout, layout) } -> same_as<void*>;
+ alloc.dealloc(ptr, layout);
+ };
+
+class GlobalHeap
+{
+public:
+ static void* alloc(const layout&);
+ static void* realloc(void* ptr, const layout& old, const layout& new_layout);
+ static void dealloc(void* ptr, const layout&);
+
+ constexpr bool operator==(const GlobalHeap&) const { return true; }
+};
+static_assert(allocator<GlobalHeap>);
+
+using DefaultAllocator = GlobalHeap;
+
+template<typename T>
+T* alloc_new(allocator auto& a, auto&&... args)
+{
+ void* ptr = a.alloc(layout::of<T>());
+ return construct_at<T>(ptr, ASL_FWD(args)...);
+}
+
+template<typename T>
+void alloc_delete(allocator auto& a, T* ptr)
+{
+ destroy(ptr);
+ a.dealloc(ptr, layout::of<T>());
+}
+
+template<typename T>
+constexpr T* alloc_new_default(auto&&... args)
+{
+ return alloc_new<T>(DefaultAllocator{}, ASL_FWD(args)...);
+}
+
+template<typename T>
+void alloc_delete_default(T* ptr)
+{
+ alloc_delete(DefaultAllocator{}, ptr);
+}
+
+} // namespace asl
diff --git a/asl/annotations.hpp b/asl/annotations.hpp
index fc65378..6ea3a84 100644
--- a/asl/annotations.hpp
+++ b/asl/annotations.hpp
@@ -1,9 +1,9 @@
-#pragma once
-
-#include "asl/config.hpp"
-
-#if ASL_COMPILER_CLANG_CL
- #define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
-#elif ASL_COMPILER_CLANG
- #define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]]
-#endif
+#pragma once
+
+#include "asl/config.hpp"
+
+#if ASL_COMPILER_CLANG_CL
+ #define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
+#elif ASL_COMPILER_CLANG
+ #define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]]
+#endif
diff --git a/asl/assert.hpp b/asl/assert.hpp
index bf6a795..7a3ae00 100644
--- a/asl/assert.hpp
+++ b/asl/assert.hpp
@@ -1,33 +1,33 @@
-#pragma once
-
-#include "asl/config.hpp"
-#include "asl/meta.hpp"
-
-namespace asl
-{
-
-void report_assert_failure( const char* msg, const source_location& sl = source_location{});
-
-} // namespace asl
-
-#if ASL_COMPILER_CLANG_CL
- #define ASL_DEBUG_BREAK() __debugbreak()
-#elif ASL_COMPILER_CLANG
- #define ASL_DEBUG_BREAK() __builtin_debugtrap()
-#endif
-
-#define ASL_ASSERT(...) \
- if (__VA_ARGS__) {} \
- else \
- { \
- ::asl::report_assert_failure(#__VA_ARGS__); \
- ASL_DEBUG_BREAK(); \
- }
-
-#define ASL_ASSERT_RELEASE(...) \
- if (__VA_ARGS__) {} \
- else \
- { \
- ::asl::report_assert_failure(#__VA_ARGS__); \
- ASL_DEBUG_BREAK(); \
- }
+#pragma once
+
+#include "asl/config.hpp"
+#include "asl/meta.hpp"
+
+namespace asl
+{
+
+void report_assert_failure( const char* msg, const source_location& sl = source_location{});
+
+} // namespace asl
+
+#if ASL_COMPILER_CLANG_CL
+ #define ASL_DEBUG_BREAK() __debugbreak()
+#elif ASL_COMPILER_CLANG
+ #define ASL_DEBUG_BREAK() __builtin_debugtrap()
+#endif
+
+#define ASL_ASSERT(...) \
+ if (__VA_ARGS__) {} \
+ else \
+ { \
+ ::asl::report_assert_failure(#__VA_ARGS__); \
+ ASL_DEBUG_BREAK(); \
+ }
+
+#define ASL_ASSERT_RELEASE(...) \
+ if (__VA_ARGS__) {} \
+ else \
+ { \
+ ::asl::report_assert_failure(#__VA_ARGS__); \
+ ASL_DEBUG_BREAK(); \
+ }
diff --git a/asl/box.hpp b/asl/box.hpp
index 340a37c..f193853 100644
--- a/asl/box.hpp
+++ b/asl/box.hpp
@@ -1,115 +1,115 @@
-#pragma once
-
-#include "asl/allocator.hpp"
-#include "asl/assert.hpp"
-#include "asl/annotations.hpp"
-#include "asl/memory.hpp"
-#include "asl/utility.hpp"
-#include "asl/hash.hpp"
-
-namespace asl
-{
-
-template<is_object T, allocator Allocator = DefaultAllocator>
-class box
-{
- T* m_ptr;
- ASL_NO_UNIQUE_ADDRESS Allocator m_alloc;
-
-public:
- explicit constexpr box(niche_t)
- requires default_constructible<Allocator>
- : m_ptr{nullptr}
- , m_alloc{}
- {}
-
- constexpr box(T* ptr, Allocator alloc)
- : m_ptr{ptr}
- , m_alloc{ASL_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)}
- {}
-
- constexpr box& operator=(box&& other)
- {
- if (this == &other) { return *this; }
-
- if (m_ptr != nullptr) { reset(); }
-
- m_ptr = exchange(other.m_ptr, nullptr);
- m_alloc = ASL_MOVE(other.m_alloc);
-
- return *this;
- }
-
- box(const box&) = delete;
- box& operator=(const box&) = delete;
-
- constexpr ~box()
- {
- reset();
- }
-
- constexpr void reset()
- {
- if (m_ptr != nullptr)
- {
- destroy(m_ptr);
- m_alloc.dealloc(m_ptr, layout::of<T>());
- m_ptr = nullptr;
- }
- }
-
- constexpr T* get() const { return m_ptr; }
-
- constexpr T& operator*() const
- {
- ASL_ASSERT(m_ptr != nullptr);
- return *m_ptr;
- }
-
- constexpr T* operator->() const
- {
- ASL_ASSERT(m_ptr != nullptr);
- return m_ptr;
- }
-
- constexpr bool operator==(niche_t) const
- {
- return m_ptr == nullptr;
- }
-
- template<typename H>
- requires hashable<T>
- friend H AslHashValue(H h, const box& b)
- {
- return H::combine(ASL_MOVE(h), *b);
- }
-};
-
-template<is_object T, allocator Allocator = DefaultAllocator, typename... Args>
-constexpr box<T, Allocator> make_box_in(Allocator allocator, Args&&... args)
- requires constructible_from<T, Args&&...>
-{
- void* raw_ptr = allocator.alloc(layout::of<T>());
- auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
- return box(ptr, ASL_MOVE(allocator));
-}
-
-template<is_object T, allocator Allocator = DefaultAllocator, typename... Args>
-constexpr box<T, Allocator> make_box(Args&&... args)
- requires default_constructible<Allocator> && constructible_from<T, Args&&...>
-{
- Allocator allocator{};
- void* raw_ptr = allocator.alloc(layout::of<T>());
- auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
- return box<T>(ptr, ASL_MOVE(allocator));
-}
-
-} // namespace asl
-
+#pragma once
+
+#include "asl/allocator.hpp"
+#include "asl/assert.hpp"
+#include "asl/annotations.hpp"
+#include "asl/memory.hpp"
+#include "asl/utility.hpp"
+#include "asl/hash.hpp"
+
+namespace asl
+{
+
+template<is_object T, allocator Allocator = DefaultAllocator>
+class box
+{
+ T* m_ptr;
+ ASL_NO_UNIQUE_ADDRESS Allocator m_alloc;
+
+public:
+ explicit constexpr box(niche_t)
+ requires default_constructible<Allocator>
+ : m_ptr{nullptr}
+ , m_alloc{}
+ {}
+
+ constexpr box(T* ptr, Allocator alloc)
+ : m_ptr{ptr}
+ , m_alloc{ASL_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)}
+ {}
+
+ constexpr box& operator=(box&& other)
+ {
+ if (this == &other) { return *this; }
+
+ if (m_ptr != nullptr) { reset(); }
+
+ m_ptr = exchange(other.m_ptr, nullptr);
+ m_alloc = ASL_MOVE(other.m_alloc);
+
+ return *this;
+ }
+
+ box(const box&) = delete;
+ box& operator=(const box&) = delete;
+
+ constexpr ~box()
+ {
+ reset();
+ }
+
+ constexpr void reset()
+ {
+ if (m_ptr != nullptr)
+ {
+ destroy(m_ptr);
+ m_alloc.dealloc(m_ptr, layout::of<T>());
+ m_ptr = nullptr;
+ }
+ }
+
+ constexpr T* get() const { return m_ptr; }
+
+ constexpr T& operator*() const
+ {
+ ASL_ASSERT(m_ptr != nullptr);
+ return *m_ptr;
+ }
+
+ constexpr T* operator->() const
+ {
+ ASL_ASSERT(m_ptr != nullptr);
+ return m_ptr;
+ }
+
+ constexpr bool operator==(niche_t) const
+ {
+ return m_ptr == nullptr;
+ }
+
+ template<typename H>
+ requires hashable<T>
+ friend H AslHashValue(H h, const box& b)
+ {
+ return H::combine(ASL_MOVE(h), *b);
+ }
+};
+
+template<is_object T, allocator Allocator = DefaultAllocator, typename... Args>
+constexpr box<T, Allocator> make_box_in(Allocator allocator, Args&&... args)
+ requires constructible_from<T, Args&&...>
+{
+ void* raw_ptr = allocator.alloc(layout::of<T>());
+ auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
+ return box(ptr, ASL_MOVE(allocator));
+}
+
+template<is_object T, allocator Allocator = DefaultAllocator, typename... Args>
+constexpr box<T, Allocator> make_box(Args&&... args)
+ requires default_constructible<Allocator> && constructible_from<T, Args&&...>
+{
+ Allocator allocator{};
+ void* raw_ptr = allocator.alloc(layout::of<T>());
+ auto* ptr = construct_at<T>(raw_ptr, ASL_FWD(args)...);
+ return box<T>(ptr, ASL_MOVE(allocator));
+}
+
+} // namespace asl
+
diff --git a/asl/buffer.hpp b/asl/buffer.hpp
index b714e5a..5cf9964 100644
--- a/asl/buffer.hpp
+++ b/