From 3ad39e9878310e5317ee73c9b353c1e2c1c5c4ee Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sat, 11 Jul 2026 22:48:30 +0800 Subject: lib: establish Zircon libc++ and KTL foundation --- third_party/libcxx/include/c++/v1/stack | 387 ++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 third_party/libcxx/include/c++/v1/stack (limited to 'third_party/libcxx/include/c++/v1/stack') diff --git a/third_party/libcxx/include/c++/v1/stack b/third_party/libcxx/include/c++/v1/stack new file mode 100644 index 0000000..537b822 --- /dev/null +++ b/third_party/libcxx/include/c++/v1/stack @@ -0,0 +1,387 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_STACK +#define _LIBCPP_STACK + +/* + stack synopsis + +namespace std +{ + +template > +class stack +{ +public: + typedef Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + +protected: + container_type c; + +public: + stack() = default; + ~stack() = default; + + stack(const stack& q) = default; + stack(stack&& q) = default; + + stack& operator=(const stack& q) = default; + stack& operator=(stack&& q) = default; + + explicit stack(const container_type& c); + explicit stack(container_type&& c); + template stack(InputIterator first, InputIterator last); // since C++23 + template R> stack(from_range_t, R&& rg); // since C++23 + template explicit stack(const Alloc& a); + template stack(const container_type& c, const Alloc& a); + template stack(container_type&& c, const Alloc& a); + template stack(const stack& c, const Alloc& a); + template stack(stack&& c, const Alloc& a); + template + stack(InputIterator first, InputIterator last, const Alloc&); // since C++23 + template R, class Alloc> + stack(from_range_t, R&& rg, const Alloc&); // since C++23 + + bool empty() const; + size_type size() const; + reference top(); + const_reference top() const; + + void push(const value_type& x); + void push(value_type&& x); + template R> + void push_range(R&& rg); // C++23 + template reference emplace(Args&&... args); // reference in C++17 + void pop(); + + void swap(stack& c) noexcept(is_nothrow_swappable_v) +}; + +template + stack(Container) -> stack; // C++17 + +template + stack(InputIterator, InputIterator) -> stack>; // since C++23 + +template + stack(from_range_t, R&&) -> stack>; // since C++23 + +template + stack(Container, Allocator) -> stack; // C++17 + +template + stack(InputIterator, InputIterator, Allocator) + -> stack, + deque, Allocator>>; // since C++23 + +template + stack(from_range_t, R&&, Allocator) + -> stack, deque, Allocator>>; // since C++23 + +template + bool operator==(const stack& x, const stack& y); +template + bool operator< (const stack& x, const stack& y); +template + bool operator!=(const stack& x, const stack& y); +template + bool operator> (const stack& x, const stack& y); +template + bool operator>=(const stack& x, const stack& y); +template + bool operator<=(const stack& x, const stack& y); +template + compare_three_way_result_t + operator<=>(const stack& x, const stack& y); // since C++20 + +template + void swap(stack& x, stack& y) + noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) +# include <__cxx03/stack> +#else +# include <__algorithm/ranges_copy.h> +# include <__config> +# include <__fwd/stack.h> +# include <__iterator/back_insert_iterator.h> +# include <__iterator/iterator_traits.h> +# include <__memory/uses_allocator.h> +# include <__ranges/access.h> +# include <__ranges/concepts.h> +# include <__ranges/container_compatible_range.h> +# include <__ranges/from_range.h> +# include <__type_traits/is_same.h> +# include <__utility/forward.h> +# include +# include + +// standard-mandated includes + +// [stack.syn] +# include +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_PUSH_MACROS +# include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); + +template +_LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); + +template */> +class stack { +public: + typedef _Container container_type; + typedef typename container_type::value_type value_type; + typedef typename container_type::reference reference; + typedef typename container_type::const_reference const_reference; + typedef typename container_type::size_type size_type; + static_assert(is_same<_Tp, value_type>::value, ""); + +protected: + container_type c; + +public: + _LIBCPP_HIDE_FROM_ABI stack() _NOEXCEPT_(is_nothrow_default_constructible::value) : c() {} + + _LIBCPP_HIDE_FROM_ABI stack(const stack& __q) : c(__q.c) {} + + _LIBCPP_HIDE_FROM_ABI stack& operator=(const stack& __q) { + c = __q.c; + return *this; + } + +# ifndef _LIBCPP_CXX03_LANG + _LIBCPP_HIDE_FROM_ABI stack(stack&& __q) noexcept(is_nothrow_move_constructible::value) + : c(std::move(__q.c)) {} + + _LIBCPP_HIDE_FROM_ABI stack& operator=(stack&& __q) noexcept(is_nothrow_move_assignable::value) { + c = std::move(__q.c); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI explicit stack(container_type&& __c) : c(std::move(__c)) {} +# endif // _LIBCPP_CXX03_LANG + + _LIBCPP_HIDE_FROM_ABI explicit stack(const container_type& __c) : c(__c) {} + + template + _LIBCPP_HIDE_FROM_ABI explicit stack(const _Alloc& __a, + __enable_if_t::value>* = 0) + : c(__a) {} + template + _LIBCPP_HIDE_FROM_ABI + stack(const container_type& __c, const _Alloc& __a, __enable_if_t::value>* = 0) + : c(__c, __a) {} + template + _LIBCPP_HIDE_FROM_ABI + stack(const stack& __s, const _Alloc& __a, __enable_if_t::value>* = 0) + : c(__s.c, __a) {} +# ifndef _LIBCPP_CXX03_LANG + template + _LIBCPP_HIDE_FROM_ABI + stack(container_type&& __c, const _Alloc& __a, __enable_if_t::value>* = 0) + : c(std::move(__c), __a) {} + template + _LIBCPP_HIDE_FROM_ABI + stack(stack&& __s, const _Alloc& __a, __enable_if_t::value>* = 0) + : c(std::move(__s.c), __a) {} +# endif // _LIBCPP_CXX03_LANG + +# if _LIBCPP_STD_VER >= 23 + template ::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last) : c(__first, __last) {} + + template <_ContainerCompatibleRange<_Tp> _Range> + _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {} + + template ::value, int> = 0, + __enable_if_t::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI stack(_InputIterator __first, _InputIterator __last, const _Alloc& __alloc) + : c(__first, __last, __alloc) {} + + template <_ContainerCompatibleRange<_Tp> _Range, + class _Alloc, + __enable_if_t::value, int> = 0> + _LIBCPP_HIDE_FROM_ABI stack(from_range_t, _Range&& __range, const _Alloc& __alloc) + : c(from_range, std::forward<_Range>(__range), __alloc) {} + +# endif + + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference top() { return c.back(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.back(); } + + _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); } +# ifndef _LIBCPP_CXX03_LANG + _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); } + +# if _LIBCPP_STD_VER >= 23 + template <_ContainerCompatibleRange<_Tp> _Range> + _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) { + if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) { + c.append_range(std::forward<_Range>(__range)); + } else { + ranges::copy(std::forward<_Range>(__range), std::back_inserter(c)); + } + } +# endif + + template + _LIBCPP_HIDE_FROM_ABI +# if _LIBCPP_STD_VER >= 17 + decltype(auto) + emplace(_Args&&... __args) { + return c.emplace_back(std::forward<_Args>(__args)...); + } +# else + void + emplace(_Args&&... __args) { + c.emplace_back(std::forward<_Args>(__args)...); + } +# endif +# endif // _LIBCPP_CXX03_LANG + + _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_back(); } + + _LIBCPP_HIDE_FROM_ABI void swap(stack& __s) _NOEXCEPT_(__is_nothrow_swappable_v) { + using std::swap; + swap(c, __s.c); + } + + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; } + + template + friend _LIBCPP_HIDE_FROM_ABI bool + operator==(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); + + template + friend _LIBCPP_HIDE_FROM_ABI bool + operator<(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); + +# if _LIBCPP_STD_VER >= 20 + template + friend _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_OtherContainer> + operator<=>(const stack<_T1, _OtherContainer>& __x, const stack<_T1, _OtherContainer>& __y); +# endif +}; + +# if _LIBCPP_STD_VER >= 17 +template >> +stack(_Container) -> stack; + +template >, + class = enable_if_t::value> > +stack(_Container, _Alloc) -> stack; +# endif + +# if _LIBCPP_STD_VER >= 23 +template ::value, int> = 0> +stack(_InputIterator, _InputIterator) -> stack<__iterator_value_type<_InputIterator>>; + +template +stack(from_range_t, _Range&&) -> stack>; + +template ::value, int> = 0, + __enable_if_t<__is_allocator_v<_Alloc>, int> = 0> +stack(_InputIterator, _InputIterator, _Alloc) + -> stack<__iterator_value_type<_InputIterator>, deque<__iterator_value_type<_InputIterator>, _Alloc>>; + +template , int> = 0> +stack(from_range_t, _Range&&, _Alloc) + -> stack, deque, _Alloc>>; + +# endif + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return __x.c == __y.c; +} + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator<(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return __x.c < __y.c; +} + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return !(__x == __y); +} + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return __y < __x; +} + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return !(__x < __y); +} + +template +inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return !(__y < __x); +} + +# if _LIBCPP_STD_VER >= 20 + +template +_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container> +operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return __x.c <=> __y.c; +} + +# endif + +template , int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { + __x.swap(__y); +} + +template +struct uses_allocator, _Alloc> : public uses_allocator<_Container, _Alloc> {}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 +# include +# include +# include +# endif +#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) + +#endif // _LIBCPP_STACK -- cgit v1.2.3