2010-05-11 21:42:16 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- stack -----------------------------------===//
|
|
|
|
//
|
2010-05-11 23:36:01 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_STACK
|
|
|
|
#define _LIBCPP_STACK
|
|
|
|
|
|
|
|
/*
|
|
|
|
stack synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T, class Container = deque<T>>
|
|
|
|
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:
|
|
|
|
explicit stack();
|
|
|
|
explicit stack(const container_type& c);
|
|
|
|
explicit stack(container_type&& c);
|
|
|
|
stack(stack&& s);
|
|
|
|
stack& operator=(stack&& s);
|
|
|
|
template <class Alloc> explicit stack(const Alloc& a);
|
|
|
|
template <class Alloc> stack(const container_type& c, const Alloc& a);
|
|
|
|
template <class Alloc> stack(container_type&& c, const Alloc& a);
|
|
|
|
template <class Alloc> 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 <class... Args> void emplace(Args&&... args);
|
|
|
|
void pop();
|
|
|
|
|
|
|
|
void swap(stack& c);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
template <class T, class Container>
|
|
|
|
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
|
|
|
|
template <class T, class Container>
|
|
|
|
void swap(stack<T, Container>& x, stack<T, Container>& y);
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
#pragma GCC system_header
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
template <class _Tp, class _Container> class stack;
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
bool
|
|
|
|
operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
|
|
|
bool
|
|
|
|
operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
|
|
|
|
|
|
|
|
template <class _Tp, class _Container = deque<_Tp> >
|
2010-09-23 19:31:07 +02:00
|
|
|
class _LIBCPP_VISIBLE stack
|
2010-05-11 21:42:16 +02:00
|
|
|
{
|
|
|
|
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:
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack() : c() {}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
explicit stack(const container_type& __c) : c(__c) {}
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
explicit stack(container_type&& __c) : c(_STD::move(__c)) {}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack(stack&& __s) : c(_STD::move(__s.c)) {}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack& operator=(stack&& __s) {c = _STD::move(__s.c); return *this;}
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
template <class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
explicit stack(const _Alloc& __a,
|
|
|
|
typename enable_if<uses_allocator<container_type,
|
|
|
|
_Alloc>::value>::type* = 0)
|
|
|
|
: c(__a) {}
|
|
|
|
template <class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack(const container_type& __c, const _Alloc& __a,
|
|
|
|
typename enable_if<uses_allocator<container_type,
|
|
|
|
_Alloc>::value>::type* = 0)
|
|
|
|
: c(__c, __a) {}
|
|
|
|
template <class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack(const stack& __s, const _Alloc& __a,
|
|
|
|
typename enable_if<uses_allocator<container_type,
|
|
|
|
_Alloc>::value>::type* = 0)
|
|
|
|
: c(__s.c, __a) {}
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
template <class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack(container_type&& __c, const _Alloc& __a,
|
|
|
|
typename enable_if<uses_allocator<container_type,
|
|
|
|
_Alloc>::value>::type* = 0)
|
|
|
|
: c(_STD::move(__c), __a) {}
|
|
|
|
template <class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
stack(stack&& __s, const _Alloc& __a,
|
|
|
|
typename enable_if<uses_allocator<container_type,
|
|
|
|
_Alloc>::value>::type* = 0)
|
|
|
|
: c(_STD::move(__s.c), __a) {}
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool empty() const {return c.empty();}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
size_type size() const {return c.size();}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
reference top() {return c.back();}
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
const_reference top() const {return c.back();}
|
|
|
|
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
void push(const value_type& __v) {c.push_back(__v);}
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
void push(value_type&& __v) {c.push_back(_STD::move(__v));}
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
2010-09-23 19:31:07 +02:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void emplace(_Args&&... __args)
|
2010-05-11 21:42:16 +02:00
|
|
|
{c.emplace_back(_STD::forward<_Args>(__args)...);}
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
void pop() {c.pop_back();}
|
|
|
|
|
2010-09-23 19:31:07 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
void swap(stack& __s)
|
|
|
|
{
|
|
|
|
using _STD::swap;
|
|
|
|
swap(c, __s.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T1, class _C1>
|
|
|
|
friend
|
|
|
|
bool
|
|
|
|
operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
|
2010-08-22 02:02:43 +02:00
|
|
|
|
2010-05-11 21:42:16 +02:00
|
|
|
template <class T1, class _C1>
|
|
|
|
friend
|
|
|
|
bool
|
|
|
|
operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return __x.c == __y.c;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return __x.c < __y.c;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
bool
|
|
|
|
operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container>
|
2010-09-23 19:31:07 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
void
|
|
|
|
swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
|
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Container, class _Alloc>
|
2010-09-23 19:31:07 +02:00
|
|
|
struct _LIBCPP_VISIBLE uses_allocator<stack<_Tp, _Container>, _Alloc>
|
2010-05-11 21:42:16 +02:00
|
|
|
: public uses_allocator<_Container, _Alloc>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
|
|
|
#endif // _LIBCPP_STACK
|