NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
compressed_pair.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_UTILITY_COMPRESSED_PAIR_HPP__
2#define NEFORCE_CORE_UTILITY_COMPRESSED_PAIR_HPP__
3
11
13NEFORCE_BEGIN_NAMESPACE__
14
20
30template <typename IfEmpty, typename T, bool Compressed = is_empty_v<IfEmpty> && !is_final_v<IfEmpty>>
31struct compressed_pair final : IfEmpty, icommon<compressed_pair<IfEmpty, T, Compressed>> {
32 using base_type = IfEmpty;
33
35
40 value() {}
41
48
55 value = _NEFORCE move(pir.value);
56 return *this;
57 }
58
65
72 value = _NEFORCE move(pir.value);
73 return *this;
74 }
75
83 template <typename... Args, enable_if_t<is_constructible_v<T, Args...>, int> = 0>
84 constexpr explicit compressed_pair(default_construct_tag, Args&&... args) noexcept(
86 IfEmpty(),
87 value(_NEFORCE forward<Args>(args)...) {}
88
98 template <typename ToEmpty, typename... Args,
100 constexpr explicit compressed_pair(exact_arg_construct_tag, ToEmpty&& first, Args&&... args) noexcept(
102 IfEmpty(_NEFORCE forward<ToEmpty>(first)),
103 value(_NEFORCE forward<Args>(args)...) {}
104
109 constexpr compressed_pair& get_base() noexcept { return *this; }
110
115 constexpr const compressed_pair& get_base() const noexcept { return *this; }
116
121 constexpr void swap(compressed_pair& rhs) noexcept(is_nothrow_swappable_v<T>) { _NEFORCE swap(value, rhs.value); }
122
127 constexpr size_t to_hash() const noexcept(noexcept(hash<T>{}(value))) { return hash<T>{}(value); }
128
134 constexpr bool operator==(const compressed_pair& y) const noexcept(noexcept(this->value == y.value)) {
135 return this->value == y.value;
136 }
137
143 constexpr bool operator<(const compressed_pair& y) const noexcept(noexcept(this->value < y.value)) {
144 return this->value < y.value;
145 }
146};
147
148
156template <typename IfEmpty, typename T>
157struct compressed_pair<IfEmpty, T, false> final : icommon<compressed_pair<IfEmpty, T, false>> {
160
168
177
183 constexpr compressed_pair& operator=(const compressed_pair& pir) noexcept(
185 no_compressed = pir.no_compressed;
186 value = pir.value;
187 return *this;
188 }
189
198
204 constexpr compressed_pair& operator=(compressed_pair&& pir) noexcept(
206 no_compressed = _NEFORCE move(pir.no_compressed);
207 value = _NEFORCE move(pir.value);
208 return *this;
209 }
210
216 template <typename... Args>
217 constexpr explicit compressed_pair(default_construct_tag, Args&&... args) noexcept(
220 value(_NEFORCE forward<Args>(args)...) {}
221
229 template <typename ToEmpty, typename... Args>
230 constexpr compressed_pair(exact_arg_construct_tag, ToEmpty&& first, Args&&... args) noexcept(
232 no_compressed(_NEFORCE forward<ToEmpty>(first)),
233 value(_NEFORCE forward<Args>(args)...) {}
234
239 constexpr IfEmpty& get_base() noexcept { return no_compressed; }
240
245 constexpr const IfEmpty& get_base() const noexcept { return no_compressed; }
246
251 constexpr void
253 _NEFORCE swap(value, rhs.value);
254 _NEFORCE swap(no_compressed, rhs.no_compressed);
255 }
256
261 constexpr size_t to_hash() const noexcept(noexcept(hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value))) {
262 return hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value);
263 }
264
270 constexpr bool operator==(const compressed_pair& y) const
271 noexcept(noexcept(this->no_compressed == y.no_compressed && this->value == y.value)) {
272 return this->no_compressed == y.no_compressed && this->value == y.value;
273 }
274
280 constexpr bool operator<(const compressed_pair& y) const
281 noexcept(noexcept(this->no_compressed < y.no_compressed ||
282 (!(y.no_compressed < this->no_compressed) && this->value < y.value))) {
283 return this->no_compressed < y.no_compressed ||
284 (!(y.no_compressed < this->no_compressed) && this->value < y.value);
285 }
286};
287
288#ifdef NEFORCE_STANDARD_17
289template <typename IfEmpty, typename T>
291#endif
292 // CompressedPair
294
295NEFORCE_END_NAMESPACE__
296#endif // NEFORCE_CORE_UTILITY_COMPRESSED_PAIR_HPP__
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
void swap()=delete
删除无参数的swap重载
NEFORCE_INLINE17 constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_default_constructible_v
is_nothrow_default_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_copy_assignable_v
is_nothrow_copy_assignable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_move_assignable_v
is_nothrow_move_assignable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_constructible_v
is_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_move_constructible_v
is_nothrow_move_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_nothrow_copy_constructible_v
is_nothrow_copy_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool conjunction_v
conjunction的便捷变量模板
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
基本接口基类
constexpr const IfEmpty & get_base() const noexcept
获取基类常量引用
constexpr compressed_pair() noexcept(conjunction_v< is_nothrow_default_constructible< IfEmpty >, is_nothrow_default_constructible< T > >)
默认构造函数
constexpr void swap(compressed_pair &rhs) noexcept(conjunction_v< is_nothrow_swappable< IfEmpty >, is_nothrow_swappable< T > >)
交换两个压缩对
constexpr compressed_pair(const compressed_pair &pir) noexcept(conjunction_v< is_nothrow_copy_constructible< IfEmpty >, is_nothrow_copy_constructible< T > >)
拷贝构造函数
constexpr compressed_pair(default_construct_tag, Args &&... args) noexcept(conjunction_v< is_nothrow_default_constructible< IfEmpty >, is_nothrow_constructible< T, Args... > >)
默认构造标签构造函数
constexpr compressed_pair(compressed_pair &&pir) noexcept(conjunction_v< is_nothrow_move_constructible< IfEmpty >, is_nothrow_move_constructible< T > >)
移动构造函数
constexpr size_t to_hash() const noexcept(noexcept(hash< IfEmpty >{}(no_compressed) ^ hash< T >{}(value)))
计算哈希值
constexpr compressed_pair(exact_arg_construct_tag, ToEmpty &&first, Args &&... args) noexcept(conjunction_v< is_nothrow_constructible< IfEmpty, ToEmpty >, is_nothrow_constructible< T, Args... > >)
精确参数构造标签构造函数
constexpr compressed_pair & operator=(compressed_pair &&pir) noexcept(conjunction_v< is_nothrow_move_assignable< IfEmpty >, is_nothrow_move_assignable< T > >)
移动赋值运算符
constexpr bool operator==(const compressed_pair &y) const noexcept(noexcept(this->no_compressed==y.no_compressed &&this->value==y.value))
相等比较运算符
IfEmpty no_compressed
未压缩的基类成员
constexpr compressed_pair & operator=(const compressed_pair &pir) noexcept(conjunction_v< is_nothrow_copy_assignable< IfEmpty >, is_nothrow_copy_assignable< T > >)
拷贝赋值运算符
constexpr IfEmpty & get_base() noexcept
获取基类引用
constexpr bool operator<(const compressed_pair &y) const noexcept(noexcept(this->no_compressed< y.no_compressed||(!(y.no_compressed< this->no_compressed) &&this->value< y.value)))
小于比较运算符
压缩对主模板,使用EBCO优化
constexpr compressed_pair() noexcept(is_nothrow_default_constructible_v< T >)
默认构造函数
constexpr void swap(compressed_pair &rhs) noexcept(is_nothrow_swappable_v< T >)
交换两个压缩对
constexpr compressed_pair(compressed_pair &&p) noexcept(is_nothrow_move_constructible_v< T >)
移动构造函数
constexpr compressed_pair(default_construct_tag, Args &&... args) noexcept(conjunction_v< is_nothrow_default_constructible< IfEmpty >, is_nothrow_constructible< T, Args... > >)
默认构造标签构造函数
constexpr bool operator<(const compressed_pair &y) const noexcept(noexcept(this->value< y.value))
小于比较运算符
constexpr bool operator==(const compressed_pair &y) const noexcept(noexcept(this->value==y.value))
相等比较运算符
constexpr compressed_pair & operator=(compressed_pair &&pir) noexcept(is_nothrow_move_assignable_v< T >)
移动赋值运算符
constexpr compressed_pair & operator=(const compressed_pair &pir) noexcept(is_nothrow_copy_assignable_v< T >)
拷贝赋值运算符
constexpr compressed_pair & get_base() noexcept
获取基类引用
constexpr const compressed_pair & get_base() const noexcept
获取基类常量引用
IfEmpty base_type
基类类型
constexpr compressed_pair(exact_arg_construct_tag, ToEmpty &&first, Args &&... args) noexcept(conjunction_v< is_nothrow_constructible< IfEmpty, ToEmpty >, is_nothrow_constructible< T, Args... > >)
精确参数构造标签构造函数
constexpr compressed_pair(const compressed_pair &p) noexcept(is_nothrow_copy_constructible_v< T >)
拷贝构造函数
constexpr size_t to_hash() const noexcept(noexcept(hash< T >{}(value)))
计算哈希值
默认构造标签
精确参数构造标签
哈希函数的主模板
通用接口,同时具备可比较和可哈希功能
判断类型是否可以使用指定参数构造
判断类型是否可以使用指定参数无异常构造
判断类型是否可无异常复制赋值
判断类型是否可无异常复制构造
判断类型是否可无异常默认构造
判断类型是否可无异常移动赋值
判断类型是否可无异常移动构造
判断类型是否可以与自身无异常交换