summaryrefslogtreecommitdiff
path: root/kernel/lib/libcxx/include/initializer_list
diff options
context:
space:
mode:
authorArseney300 <Arseney300@gmail.com>2026-04-12 02:01:25 +0700
committerArseney300 <Arseney300@gmail.com>2026-04-12 02:01:25 +0700
commit2496ffd6d97c3ccd3e325687442d31ab035479a1 (patch)
tree5d176669f823182fe74261f076dc11c8e8f88025 /kernel/lib/libcxx/include/initializer_list
parent496246c92dabe6757480147016490ea6ae43bb66 (diff)
bastion: add freestanding C++ standard library (libcxx)feature/freestanding-libcxx
Header-only implementation of a C++ standard library subset for the freestanding kernel, using Clang builtins wherever possible. Provides 19 public headers (~35 internal files): type_traits, utility, memory, algorithm, functional, concepts, array, string_view, span, optional, expected, variant, tuple, bit, limits, new, initializer_list, cstdint, cstddef, and source_location. Integration changes: - kernel/Makefile: add -Ilib/libcxx/include to include path - kernel/lib/string.cpp: add memchr and strncmp (needed by string_view) - kernel/lib/cxxabi.cpp: guard placement new against <new> header conflict - kernel/include/kernel/kernel.h: Panic() now uses std::source_location - kernel/core/kernel.cpp: Panic() implementation updated to match Builds cleanly on both x86_64 and aarch64 with zero new warnings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'kernel/lib/libcxx/include/initializer_list')
-rw-r--r--kernel/lib/libcxx/include/initializer_list57
1 files changed, 57 insertions, 0 deletions
diff --git a/kernel/lib/libcxx/include/initializer_list b/kernel/lib/libcxx/include/initializer_list
new file mode 100644
index 0000000..31aff39
--- /dev/null
+++ b/kernel/lib/libcxx/include/initializer_list
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the BastionOS freestanding C++ standard library.
+//
+// The compiler generates calls to std::initializer_list's private constructor.
+// The memory layout MUST match what Clang expects.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBBASTION_INITIALIZER_LIST
+#define _LIBBASTION_INITIALIZER_LIST
+
+#include <__config>
+#include <cstddef>
+
+_LIBBASTION_BEGIN_NAMESPACE_STD
+
+template<class _Ep>
+class initializer_list {
+public:
+ using value_type = _Ep;
+ using reference = const _Ep&;
+ using const_reference = const _Ep&;
+ using size_type = size_t;
+ using iterator = const _Ep*;
+ using const_iterator = const _Ep*;
+
+ _LIBBASTION_NODISCARD constexpr size_type size() const noexcept { return __size_; }
+ _LIBBASTION_NODISCARD constexpr const_iterator begin() const noexcept { return __begin_; }
+ _LIBBASTION_NODISCARD constexpr const_iterator end() const noexcept { return __begin_ + __size_; }
+
+ constexpr initializer_list() noexcept : __begin_(nullptr), __size_(0) {}
+
+private:
+ // Clang constructs initializer_list with (pointer, size).
+ // This constructor and the field order MUST match the compiler's ABI.
+ constexpr initializer_list(const _Ep* __b, size_t __s) noexcept
+ : __begin_(__b), __size_(__s) {}
+
+ const _Ep* __begin_;
+ size_t __size_;
+};
+
+template<class _Ep>
+_LIBBASTION_NODISCARD inline constexpr const _Ep* begin(initializer_list<_Ep> __il) noexcept {
+ return __il.begin();
+}
+
+template<class _Ep>
+_LIBBASTION_NODISCARD inline constexpr const _Ep* end(initializer_list<_Ep> __il) noexcept {
+ return __il.end();
+}
+
+_LIBBASTION_END_NAMESPACE_STD
+
+#endif // _LIBBASTION_INITIALIZER_LIST