HelenOS sources
This source file includes following definitions.
- empty
- top
- top
- push
- push
- emplace
- pop
- swap
- swap
#ifndef LIBCPP_BITS_ADT_STACK
#define LIBCPP_BITS_ADT_STACK
#include <deque>
#include <initializer_list>
#include <utility>
namespace std
{
template<class T, class Container = deque<T>>
class stack
{
public:
using container_type = Container;
using value_type = typename container_type::value_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using size_type = typename container_type::size_type;
explicit stack(container_type& cont)
: c{cont}
{ }
explicit stack(container_type&& cont = container_type{})
: c{move(cont)}
{ }
template<class Alloc>
explicit stack(Alloc& alloc)
: c{alloc}
{ }
template<class Alloc>
stack(const container_type& cont, const Alloc& alloc)
: c{cont, alloc}
{ }
template<class Alloc>
stack(container_type&& cont, const Alloc& alloc)
: c{move(cont), alloc}
{ }
template<class Alloc>
stack(const stack& other, const Alloc& alloc)
: c{other.c, alloc}
{ }
template<class Alloc>
stack(stack&& other, const Alloc& alloc)
: c{move(other.c), alloc}
{ }
bool empty()
{
return c.empty();
}
size_type size()
{
return c.size();
}
reference top()
{
return c.back();
}
const_reference top() const
{
return c.back();
}
void push(const value_type& val)
{
c.push_back(val);
}
void push(value_type&& val)
{
c.push_back(move(val));
}
template<class... Args>
void emplace(Args&&... args)
{
c.emplace_back(forward<Args>(args)...);
}
void pop()
{
c.pop_back();
}
void swap(stack& other)
noexcept(noexcept(declval<container_type>().swap(declval<container_type&>())))
{
std::swap(c, other.c);
}
protected:
container_type c;
};
template<class T, class Container>
bool operator==(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c == rhs.c;
}
template<class T, class Container>
bool operator!=(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c != rhs.c;
}
template<class T, class Container>
bool operator<(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c < rhs.c;
}
template<class T, class Container>
bool operator<=(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c <= rhs.c;
}
template<class T, class Container>
bool operator>(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c > rhs.c;
}
template<class T, class Container>
bool operator>=(const stack<T, Container>& lhs,
const stack<T, Container>& rhs)
{
return lhs.c >= rhs.c;
}
template<class T, class Container>
void swap(stack<T, Container>& lhs, stack<T, Container>& rhs)
noexcept(noexcept(lhs.swap(rhs)))
{
lhs.swap(rhs);
}
}
#endif
HelenOS homepage, sources at GitHub