14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===---------------------------- stack -----------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_STACK 124684ddb6SLionel Sambuc#define _LIBCPP_STACK 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc stack synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambuctemplate <class T, class Container = deque<T>> 214684ddb6SLionel Sambucclass stack 224684ddb6SLionel Sambuc{ 234684ddb6SLionel Sambucpublic: 244684ddb6SLionel Sambuc typedef Container container_type; 254684ddb6SLionel Sambuc typedef typename container_type::value_type value_type; 264684ddb6SLionel Sambuc typedef typename container_type::reference reference; 274684ddb6SLionel Sambuc typedef typename container_type::const_reference const_reference; 284684ddb6SLionel Sambuc typedef typename container_type::size_type size_type; 294684ddb6SLionel Sambuc 304684ddb6SLionel Sambucprotected: 314684ddb6SLionel Sambuc container_type c; 324684ddb6SLionel Sambuc 334684ddb6SLionel Sambucpublic: 344684ddb6SLionel Sambuc stack() = default; 354684ddb6SLionel Sambuc ~stack() = default; 364684ddb6SLionel Sambuc 374684ddb6SLionel Sambuc stack(const stack& q) = default; 384684ddb6SLionel Sambuc stack(stack&& q) = default; 394684ddb6SLionel Sambuc 404684ddb6SLionel Sambuc stack& operator=(const stack& q) = default; 414684ddb6SLionel Sambuc stack& operator=(stack&& q) = default; 424684ddb6SLionel Sambuc 434684ddb6SLionel Sambuc explicit stack(const container_type& c); 444684ddb6SLionel Sambuc explicit stack(container_type&& c); 454684ddb6SLionel Sambuc template <class Alloc> explicit stack(const Alloc& a); 464684ddb6SLionel Sambuc template <class Alloc> stack(const container_type& c, const Alloc& a); 474684ddb6SLionel Sambuc template <class Alloc> stack(container_type&& c, const Alloc& a); 484684ddb6SLionel Sambuc template <class Alloc> stack(const stack& c, const Alloc& a); 494684ddb6SLionel Sambuc template <class Alloc> stack(stack&& c, const Alloc& a); 504684ddb6SLionel Sambuc 514684ddb6SLionel Sambuc bool empty() const; 524684ddb6SLionel Sambuc size_type size() const; 534684ddb6SLionel Sambuc reference top(); 544684ddb6SLionel Sambuc const_reference top() const; 554684ddb6SLionel Sambuc 564684ddb6SLionel Sambuc void push(const value_type& x); 574684ddb6SLionel Sambuc void push(value_type&& x); 584684ddb6SLionel Sambuc template <class... Args> void emplace(Args&&... args); 594684ddb6SLionel Sambuc void pop(); 604684ddb6SLionel Sambuc 614684ddb6SLionel Sambuc void swap(stack& c) noexcept(noexcept(swap(c, q.c))); 624684ddb6SLionel Sambuc}; 634684ddb6SLionel Sambuc 644684ddb6SLionel Sambuctemplate <class T, class Container> 654684ddb6SLionel Sambuc bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); 664684ddb6SLionel Sambuctemplate <class T, class Container> 674684ddb6SLionel Sambuc bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); 684684ddb6SLionel Sambuctemplate <class T, class Container> 694684ddb6SLionel Sambuc bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); 704684ddb6SLionel Sambuctemplate <class T, class Container> 714684ddb6SLionel Sambuc bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); 724684ddb6SLionel Sambuctemplate <class T, class Container> 734684ddb6SLionel Sambuc bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); 744684ddb6SLionel Sambuctemplate <class T, class Container> 754684ddb6SLionel Sambuc bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); 764684ddb6SLionel Sambuc 774684ddb6SLionel Sambuctemplate <class T, class Container> 784684ddb6SLionel Sambuc void swap(stack<T, Container>& x, stack<T, Container>& y) 794684ddb6SLionel Sambuc noexcept(noexcept(x.swap(y))); 804684ddb6SLionel Sambuc 814684ddb6SLionel Sambuc} // std 824684ddb6SLionel Sambuc 834684ddb6SLionel Sambuc*/ 844684ddb6SLionel Sambuc 854684ddb6SLionel Sambuc#include <__config> 864684ddb6SLionel Sambuc#include <deque> 874684ddb6SLionel Sambuc 884684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 894684ddb6SLionel Sambuc#pragma GCC system_header 904684ddb6SLionel Sambuc#endif 914684ddb6SLionel Sambuc 924684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 934684ddb6SLionel Sambuc 94*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY stack; 954684ddb6SLionel Sambuc 964684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 974684ddb6SLionel Sambuc_LIBCPP_INLINE_VISIBILITY 984684ddb6SLionel Sambucbool 994684ddb6SLionel Sambucoperator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 1004684ddb6SLionel Sambuc 1014684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 1024684ddb6SLionel Sambuc_LIBCPP_INLINE_VISIBILITY 1034684ddb6SLionel Sambucbool 1044684ddb6SLionel Sambucoperator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y); 1054684ddb6SLionel Sambuc 106*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Container /*= deque<_Tp>*/> 1074684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY stack 1084684ddb6SLionel Sambuc{ 1094684ddb6SLionel Sambucpublic: 1104684ddb6SLionel Sambuc typedef _Container container_type; 1114684ddb6SLionel Sambuc typedef typename container_type::value_type value_type; 1124684ddb6SLionel Sambuc typedef typename container_type::reference reference; 1134684ddb6SLionel Sambuc typedef typename container_type::const_reference const_reference; 1144684ddb6SLionel Sambuc typedef typename container_type::size_type size_type; 1154684ddb6SLionel Sambuc 1164684ddb6SLionel Sambucprotected: 1174684ddb6SLionel Sambuc container_type c; 1184684ddb6SLionel Sambuc 1194684ddb6SLionel Sambucpublic: 1204684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1214684ddb6SLionel Sambuc stack() 1224684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) 1234684ddb6SLionel Sambuc : c() {} 1244684ddb6SLionel Sambuc 1254684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1264684ddb6SLionel Sambuc stack(const stack& __q) : c(__q.c) {} 1274684ddb6SLionel Sambuc 1284684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1294684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1304684ddb6SLionel Sambuc stack(stack&& __q) 1314684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) 1324684ddb6SLionel Sambuc : c(_VSTD::move(__q.c)) {} 1334684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1344684ddb6SLionel Sambuc 1354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1364684ddb6SLionel Sambuc stack& operator=(const stack& __q) {c = __q.c; return *this;} 1374684ddb6SLionel Sambuc 1384684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1394684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1404684ddb6SLionel Sambuc stack& operator=(stack&& __q) 1414684ddb6SLionel Sambuc _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) 1424684ddb6SLionel Sambuc {c = _VSTD::move(__q.c); return *this;} 1434684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1444684ddb6SLionel Sambuc 1454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1464684ddb6SLionel Sambuc explicit stack(const container_type& __c) : c(__c) {} 1474684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1484684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1494684ddb6SLionel Sambuc explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {} 1504684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1514684ddb6SLionel Sambuc template <class _Alloc> 1524684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1534684ddb6SLionel Sambuc explicit stack(const _Alloc& __a, 1544684ddb6SLionel Sambuc typename enable_if<uses_allocator<container_type, 1554684ddb6SLionel Sambuc _Alloc>::value>::type* = 0) 1564684ddb6SLionel Sambuc : c(__a) {} 1574684ddb6SLionel Sambuc template <class _Alloc> 1584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1594684ddb6SLionel Sambuc stack(const container_type& __c, const _Alloc& __a, 1604684ddb6SLionel Sambuc typename enable_if<uses_allocator<container_type, 1614684ddb6SLionel Sambuc _Alloc>::value>::type* = 0) 1624684ddb6SLionel Sambuc : c(__c, __a) {} 1634684ddb6SLionel Sambuc template <class _Alloc> 1644684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1654684ddb6SLionel Sambuc stack(const stack& __s, const _Alloc& __a, 1664684ddb6SLionel Sambuc typename enable_if<uses_allocator<container_type, 1674684ddb6SLionel Sambuc _Alloc>::value>::type* = 0) 1684684ddb6SLionel Sambuc : c(__s.c, __a) {} 1694684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1704684ddb6SLionel Sambuc template <class _Alloc> 1714684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1724684ddb6SLionel Sambuc stack(container_type&& __c, const _Alloc& __a, 1734684ddb6SLionel Sambuc typename enable_if<uses_allocator<container_type, 1744684ddb6SLionel Sambuc _Alloc>::value>::type* = 0) 1754684ddb6SLionel Sambuc : c(_VSTD::move(__c), __a) {} 1764684ddb6SLionel Sambuc template <class _Alloc> 1774684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1784684ddb6SLionel Sambuc stack(stack&& __s, const _Alloc& __a, 1794684ddb6SLionel Sambuc typename enable_if<uses_allocator<container_type, 1804684ddb6SLionel Sambuc _Alloc>::value>::type* = 0) 1814684ddb6SLionel Sambuc : c(_VSTD::move(__s.c), __a) {} 1824684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1834684ddb6SLionel Sambuc 1844684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1854684ddb6SLionel Sambuc bool empty() const {return c.empty();} 1864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1874684ddb6SLionel Sambuc size_type size() const {return c.size();} 1884684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1894684ddb6SLionel Sambuc reference top() {return c.back();} 1904684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1914684ddb6SLionel Sambuc const_reference top() const {return c.back();} 1924684ddb6SLionel Sambuc 1934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1944684ddb6SLionel Sambuc void push(const value_type& __v) {c.push_back(__v);} 1954684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 1974684ddb6SLionel Sambuc void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} 1984684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS 1994684ddb6SLionel Sambuc template <class... _Args> 2004684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2014684ddb6SLionel Sambuc void emplace(_Args&&... __args) 2024684ddb6SLionel Sambuc {c.emplace_back(_VSTD::forward<_Args>(__args)...);} 2034684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_VARIADICS 2044684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 2054684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2064684ddb6SLionel Sambuc void pop() {c.pop_back();} 2074684ddb6SLionel Sambuc 2084684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 2094684ddb6SLionel Sambuc void swap(stack& __s) 2104684ddb6SLionel Sambuc _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) 2114684ddb6SLionel Sambuc { 2124684ddb6SLionel Sambuc using _VSTD::swap; 2134684ddb6SLionel Sambuc swap(c, __s.c); 2144684ddb6SLionel Sambuc } 2154684ddb6SLionel Sambuc 2164684ddb6SLionel Sambuc template <class T1, class _C1> 2174684ddb6SLionel Sambuc friend 2184684ddb6SLionel Sambuc bool 2194684ddb6SLionel Sambuc operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); 2204684ddb6SLionel Sambuc 2214684ddb6SLionel Sambuc template <class T1, class _C1> 2224684ddb6SLionel Sambuc friend 2234684ddb6SLionel Sambuc bool 2244684ddb6SLionel Sambuc operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y); 2254684ddb6SLionel Sambuc}; 2264684ddb6SLionel Sambuc 2274684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2284684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2294684ddb6SLionel Sambucbool 2304684ddb6SLionel Sambucoperator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2314684ddb6SLionel Sambuc{ 2324684ddb6SLionel Sambuc return __x.c == __y.c; 2334684ddb6SLionel Sambuc} 2344684ddb6SLionel Sambuc 2354684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2364684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2374684ddb6SLionel Sambucbool 2384684ddb6SLionel Sambucoperator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2394684ddb6SLionel Sambuc{ 2404684ddb6SLionel Sambuc return __x.c < __y.c; 2414684ddb6SLionel Sambuc} 2424684ddb6SLionel Sambuc 2434684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2444684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2454684ddb6SLionel Sambucbool 2464684ddb6SLionel Sambucoperator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2474684ddb6SLionel Sambuc{ 2484684ddb6SLionel Sambuc return !(__x == __y); 2494684ddb6SLionel Sambuc} 2504684ddb6SLionel Sambuc 2514684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2524684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2534684ddb6SLionel Sambucbool 2544684ddb6SLionel Sambucoperator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2554684ddb6SLionel Sambuc{ 2564684ddb6SLionel Sambuc return __y < __x; 2574684ddb6SLionel Sambuc} 2584684ddb6SLionel Sambuc 2594684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2604684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2614684ddb6SLionel Sambucbool 2624684ddb6SLionel Sambucoperator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2634684ddb6SLionel Sambuc{ 2644684ddb6SLionel Sambuc return !(__x < __y); 2654684ddb6SLionel Sambuc} 2664684ddb6SLionel Sambuc 2674684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2684684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2694684ddb6SLionel Sambucbool 2704684ddb6SLionel Sambucoperator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) 2714684ddb6SLionel Sambuc{ 2724684ddb6SLionel Sambuc return !(__y < __x); 2734684ddb6SLionel Sambuc} 2744684ddb6SLionel Sambuc 2754684ddb6SLionel Sambuctemplate <class _Tp, class _Container> 2764684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2774684ddb6SLionel Sambucvoid 2784684ddb6SLionel Sambucswap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y) 2794684ddb6SLionel Sambuc _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 2804684ddb6SLionel Sambuc{ 2814684ddb6SLionel Sambuc __x.swap(__y); 2824684ddb6SLionel Sambuc} 2834684ddb6SLionel Sambuc 2844684ddb6SLionel Sambuctemplate <class _Tp, class _Container, class _Alloc> 2854684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY uses_allocator<stack<_Tp, _Container>, _Alloc> 2864684ddb6SLionel Sambuc : public uses_allocator<_Container, _Alloc> 2874684ddb6SLionel Sambuc{ 2884684ddb6SLionel Sambuc}; 2894684ddb6SLionel Sambuc 2904684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 2914684ddb6SLionel Sambuc 2924684ddb6SLionel Sambuc#endif // _LIBCPP_STACK 293