// -*- C++ -*- //===---------------------------- stack -----------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #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 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); 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 reference emplace(Args&&... args); // reference in C++17 void pop(); void swap(stack& c) noexcept(is_nothrow_swappable_v) }; 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 void swap(stack& x, stack& y) noexcept(noexcept(x.swap(y))); } // std */ #include <__config> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif _LIBCPP_BEGIN_NAMESPACE_STD template > class _LIBCPP_TEMPLATE_VIS stack; template _LIBCPP_INLINE_VISIBILITY bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); template _LIBCPP_INLINE_VISIBILITY bool operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); template */> class _LIBCPP_TEMPLATE_VIS 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_INLINE_VISIBILITY stack() _NOEXCEPT_(is_nothrow_default_constructible::value) : c() {} _LIBCPP_INLINE_VISIBILITY stack(const stack& __q) : c(__q.c) {} _LIBCPP_INLINE_VISIBILITY stack& operator=(const stack& __q) {c = __q.c; return *this;} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY stack(stack&& __q) _NOEXCEPT_(is_nothrow_move_constructible::value) : c(_VSTD::move(__q.c)) {} _LIBCPP_INLINE_VISIBILITY stack& operator=(stack&& __q) _NOEXCEPT_(is_nothrow_move_assignable::value) {c = _VSTD::move(__q.c); return *this;} _LIBCPP_INLINE_VISIBILITY explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY explicit stack(const container_type& __c) : c(__c) {} template _LIBCPP_INLINE_VISIBILITY explicit stack(const _Alloc& __a, typename enable_if::value>::type* = 0) : c(__a) {} template _LIBCPP_INLINE_VISIBILITY stack(const container_type& __c, const _Alloc& __a, typename enable_if::value>::type* = 0) : c(__c, __a) {} template _LIBCPP_INLINE_VISIBILITY stack(const stack& __s, const _Alloc& __a, typename enable_if::value>::type* = 0) : c(__s.c, __a) {} #ifndef _LIBCPP_CXX03_LANG template _LIBCPP_INLINE_VISIBILITY stack(container_type&& __c, const _Alloc& __a, typename enable_if::value>::type* = 0) : c(_VSTD::move(__c), __a) {} template _LIBCPP_INLINE_VISIBILITY stack(stack&& __s, const _Alloc& __a, typename enable_if::value>::type* = 0) : c(_VSTD::move(__s.c), __a) {} #endif // _LIBCPP_CXX03_LANG _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} _LIBCPP_INLINE_VISIBILITY reference top() {return c.back();} _LIBCPP_INLINE_VISIBILITY const_reference top() const {return c.back();} _LIBCPP_INLINE_VISIBILITY void push(const value_type& __v) {c.push_back(__v);} #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} template _LIBCPP_INLINE_VISIBILITY #if _LIBCPP_STD_VER > 14 decltype(auto) emplace(_Args&&... __args) { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} #else void emplace(_Args&&... __args) { c.emplace_back(_VSTD::forward<_Args>(__args)...);} #endif #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void pop() {c.pop_back();} _LIBCPP_INLINE_VISIBILITY void swap(stack& __s) _NOEXCEPT_(__is_nothrow_swappable::value) { using _VSTD::swap; swap(c, __s.c); } template friend bool operator==(const stack& __x, const stack& __y); template friend bool operator< (const stack& __x, const stack& __y); }; template inline _LIBCPP_INLINE_VISIBILITY bool operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return __x.c == __y.c; } template inline _LIBCPP_INLINE_VISIBILITY bool operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return __x.c < __y.c; } template inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return !(__x == __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return __y < __x; } template inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return !(__x < __y); } template inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { return !(__y < __x); } template inline _LIBCPP_INLINE_VISIBILITY typename enable_if< __is_swappable<_Container>::value, void >::type swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { __x.swap(__y); } template struct _LIBCPP_TEMPLATE_VIS uses_allocator, _Alloc> : public uses_allocator<_Container, _Alloc> { }; _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_STACK