-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
3 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,8 @@ | ||
#pragma once | ||
#include <stack> | ||
#include "xr_vector.h" | ||
//#include <stack> | ||
|
||
// XXX: Use standard implementation? | ||
//template <typename T, class container = xr_vector<T>> | ||
//using xr_stack = std::stack<T, container>; | ||
|
||
// XXX: Use profiler or something to know if this is faster than std::stack | ||
template <typename _Ty, class _C = xr_vector<_Ty>> | ||
class xr_stack | ||
{ | ||
public: | ||
using allocator_type = typename _C::allocator_type; | ||
using value_type = typename allocator_type::value_type; | ||
using size_type = typename allocator_type::size_type; | ||
using _Myt = xr_stack<_Ty, _C>; | ||
|
||
allocator_type get_allocator() const { return c.get_allocator(); } | ||
bool empty() const { return c.empty(); } | ||
size_type size() const { return c.size(); } | ||
value_type& top() { return c.back(); } | ||
const value_type& top() const { return c.back(); } | ||
void emplace(value_type&& _X) { c.emplace_back(_X); } | ||
void push(value_type&& _X) { c.push_back(std::move(_X)); } | ||
void push(const value_type& _X) { c.push_back(_X); } | ||
void pop() { c.pop_back(); } | ||
bool operator==(const _Myt& _X) const { return c == _X.c; } | ||
bool operator!=(const _Myt& _X) const { return !(*this == _X); } | ||
bool operator<(const _Myt& _X) const { return c < _X.c; } | ||
bool operator>(const _Myt& _X) const { return _X < *this; } | ||
bool operator<=(const _Myt& _X) const { return !(_X < *this); } | ||
bool operator>=(const _Myt& _X) const { return !(*this < _X); } | ||
|
||
protected: | ||
_C c; | ||
}; | ||
template <typename T, class container = xr_vector<T>> | ||
using xr_stack = std::stack<T, container>; | ||
|
||
#define DEFINE_STACK(T, N) using N = xr_stack<T>; |