forked from mutouyun/nixy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriority.h
118 lines (97 loc) · 2.75 KB
/
priority.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
The Nixy Library
Code covered by the MIT License
Author: mutouyun (http://darkc.at)
*/
#pragma once
#include "nixycore/container/vector.h"
#include "nixycore/utility/rvalue.h"
#include "nixycore/general/general.h"
#include <queue> // std::priority_queue
//////////////////////////////////////////////////////////////////////////
NX_BEG
//////////////////////////////////////////////////////////////////////////
#ifdef NX_SP_CXX11_ALIAS
template
<
typename T, typename SeqT = nx::vector<T>,
typename CompT = std::less<typename SeqT::value_type>
>
using priority = std::priority_queue<T, SeqT, CompT>;
#else /*NX_SP_CXX11_ALIAS*/
template
<
typename T, typename SeqT = nx::vector<T>,
typename CompT = std::less<typename SeqT::value_type>
>
class priority : public std::priority_queue<T, SeqT, CompT>
{
typedef std::priority_queue<T, SeqT, CompT> base_t;
public:
#ifdef NX_SP_CXX11_INHERITING
using base_t::priority_queue;
#else /*NX_SP_CXX11_INHERITING*/
explicit priority(const CompT& c = CompT(), const SeqT& s = SeqT())
: base_t(c, s)
{}
template <typename IteratorT>
priority(IteratorT f, IteratorT l,
const CompT& c = CompT(), const SeqT& s = SeqT())
: base_t(f, l, c, s)
{}
priority(const priority& rhs)
: base_t(rhs)
{}
#ifdef NX_SP_CXX11_STACK_SWAP
priority(nx_rref(priority, true) rhs)
: base_t()
{
base_t::swap(moved(rhs));
}
#endif
#endif/*NX_SP_CXX11_INHERITING*/
priority& operator=(priority rhs)
{
rhs.swap(*this);
return (*this);
}
};
/*
Special swap algorithm
*/
template <typename T, typename S, typename C>
inline void swap(priority<T, S, C>& x, priority<T, S, C>& y)
{
x.swap(y);
}
#endif/*NX_SP_CXX11_ALIAS*/
/*
Special assign algorithm
*/
template <typename T, typename S, typename C, typename V>
inline void insert(std::priority_queue<T, S, C>& set,
typename std::priority_queue<T, S, C>::iterator /*ite*/, const V& val)
{
set.push(val);
}
template <typename T, typename S, typename C>
inline void erase(std::priority_queue<T, S, C>& set,
typename std::priority_queue<T, S, C>::iterator /*ite*/)
{
set.pop();
}
#ifndef NX_SP_CXX11_ALIAS
template <typename T, typename S, typename C, typename V>
inline void insert(priority<T, S, C>& set, typename priority<T, S, C>::iterator /*ite*/, const V& val)
{
set.push(val);
}
template <typename T, typename S, typename C>
inline void erase(priority<T, S, C>& set, typename priority<T, S, C>::iterator /*ite*/)
{
set.pop();
}
#endif/*NX_SP_CXX11_ALIAS*/
//////////////////////////////////////////////////////////////////////////
NX_END
//////////////////////////////////////////////////////////////////////////