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 IfEmpty(),
41 value() {}
42
48 IfEmpty(p.get_base()),
49 value(p.value) {}
50
57 value = _NEFORCE move(pir.value);
58 return *this;
59 }
60
66 IfEmpty(p.get_base()),
67 value(_NEFORCE move(p.value)) {}
68
75 value = _NEFORCE move(pir.value);
76 return *this;
77 }
78
86 template <typename... Args, enable_if_t<is_constructible_v<T, Args...>, int> = 0>
87 constexpr explicit compressed_pair(default_construct_tag /*unused*/, Args&&... args) noexcept(
89 IfEmpty(),
90 value(_NEFORCE forward<Args>(args)...) {}
91
101 template <typename ToEmpty, typename... Args,
103 constexpr explicit compressed_pair(exact_arg_construct_tag /*unused*/, ToEmpty&& first, Args&&... args) noexcept(
105 IfEmpty(_NEFORCE forward<ToEmpty>(first)),
106 value(_NEFORCE forward<Args>(args)...) {}
107
112 constexpr compressed_pair& get_base() & noexcept { return *this; }
113
118 constexpr const compressed_pair& get_base() const& noexcept { return *this; }
119
124 constexpr compressed_pair&& get_base() && noexcept { return _NEFORCE move(*this); }
125
130 constexpr const compressed_pair&& get_base() const&& noexcept { return _NEFORCE move(*this); }
131
136 constexpr void swap(compressed_pair& rhs) noexcept(is_nothrow_swappable_v<T>) { _NEFORCE swap(value, rhs.value); }
137
142 constexpr size_t to_hash() const noexcept(noexcept(hash<T>{}(value))) { return hash<T>{}(value); }
143
149 NEFORCE_NODISCARD constexpr bool equal_to(const compressed_pair& y) const
150 noexcept(noexcept(this->value == y.value)) {
151 return this->value == y.value;
152 }
153
159 NEFORCE_NODISCARD constexpr bool less_than(const compressed_pair& y) const
160 noexcept(noexcept(this->value < y.value)) {
161 return this->value < y.value;
162 }
163};
164
165
173template <typename IfEmpty, typename T>
174struct compressed_pair<IfEmpty, T, false> final : icommon<compressed_pair<IfEmpty, T, false>> {
177
185
194
200 constexpr compressed_pair& operator=(const compressed_pair& pir) noexcept(
202 no_compressed = pir.no_compressed;
203 value = pir.value;
204 return *this;
205 }
206
215
221 constexpr compressed_pair& operator=(compressed_pair&& pir) noexcept(
223 no_compressed = _NEFORCE move(pir.no_compressed);
224 value = _NEFORCE move(pir.value);
225 return *this;
226 }
227
233 template <typename... Args>
234 constexpr explicit compressed_pair(default_construct_tag /*unused*/, Args&&... args) noexcept(
237 value(_NEFORCE forward<Args>(args)...) {}
238
246 template <typename ToEmpty, typename... Args>
247 constexpr compressed_pair(exact_arg_construct_tag /*unused*/, ToEmpty&& first, Args&&... args) noexcept(
249 no_compressed(_NEFORCE forward<ToEmpty>(first)),
250 value(_NEFORCE forward<Args>(args)...) {}
251
256 constexpr IfEmpty& get_base() & noexcept { return no_compressed; }
257
262 constexpr const IfEmpty& get_base() const& noexcept { return no_compressed; }
263
268 constexpr IfEmpty&& get_base() && noexcept { return _NEFORCE move(no_compressed); }
269
274 constexpr const IfEmpty&& get_base() const&& noexcept { return _NEFORCE move(no_compressed); }
275
280 constexpr void
282 _NEFORCE swap(value, rhs.value);
283 _NEFORCE swap(no_compressed, rhs.no_compressed);
284 }
285
290 constexpr size_t to_hash() const noexcept(noexcept(hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value))) {
291 return hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value);
292 }
293
299 NEFORCE_NODISCARD constexpr bool equal_to(const compressed_pair& y) const
300 noexcept(noexcept(this->no_compressed == y.no_compressed && this->value == y.value)) {
301 return this->no_compressed == y.no_compressed && this->value == y.value;
302 }
303
309 NEFORCE_NODISCARD constexpr bool less_than(const compressed_pair& y) const
310 noexcept(noexcept(this->no_compressed < y.no_compressed ||
311 (!(y.no_compressed < this->no_compressed) && this->value < y.value))) {
312 return this->no_compressed < y.no_compressed ||
313 (!(y.no_compressed < this->no_compressed) && this->value < y.value);
314 }
315};
316
317#ifdef NEFORCE_STANDARD_17
318template <typename IfEmpty, typename T>
320#endif
321 // CompressedPair
323
324NEFORCE_END_NAMESPACE__
325#endif // NEFORCE_CORE_UTILITY_COMPRESSED_PAIR_HPP__
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重载
constexpr bool is_nothrow_swappable_v
is_nothrow_swappable的便捷变量模板
constexpr bool is_constructible_v
is_constructible的便捷变量模板
constexpr bool is_nothrow_copy_constructible_v
is_nothrow_copy_constructible的便捷变量模板
constexpr bool is_nothrow_default_constructible_v
is_nothrow_default_constructible的便捷变量模板
constexpr bool is_nothrow_copy_assignable_v
is_nothrow_copy_assignable的便捷变量模板
constexpr bool is_nothrow_move_constructible_v
is_nothrow_move_constructible的便捷变量模板
constexpr bool is_nothrow_move_assignable_v
is_nothrow_move_assignable的便捷变量模板
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 bool equal_to(const compressed_pair &y) const noexcept(noexcept(this->no_compressed==y.no_compressed &&this->value==y.value))
相等比较运算符
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 IfEmpty && get_base() &&noexcept
获取基类引用
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 less_than(const compressed_pair &y) const noexcept(noexcept(this->no_compressed< y.no_compressed||(!(y.no_compressed< this->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 const IfEmpty && get_base() const &&noexcept
获取基类常量引用
压缩对主模板,使用EBCO优化
constexpr compressed_pair() noexcept(is_nothrow_default_constructible_v< T >)
默认构造函数
constexpr void swap(compressed_pair &rhs) noexcept(is_nothrow_swappable_v< T >)
交换两个压缩对
constexpr bool less_than(const compressed_pair &y) const noexcept(noexcept(this->value< y.value))
小于比较运算符
constexpr bool equal_to(const compressed_pair &y) const noexcept(noexcept(this->value==y.value))
相等比较运算符
constexpr const compressed_pair && get_base() const &&noexcept
获取基类常量引用
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 const compressed_pair & get_base() const &noexcept
获取基类常量引用
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
获取基类引用
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 && get_base() &&noexcept
获取基类引用
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)))
计算哈希值
默认构造标签
精确参数构造标签
哈希函数的主模板
通用接口,同时具备可比较和可哈希功能
判断类型是否可以使用指定参数构造
判断类型是否可以使用指定参数无异常构造
判断类型是否可无异常复制赋值
判断类型是否可无异常复制构造
判断类型是否可无异常默认构造
判断类型是否可无异常移动赋值
判断类型是否可无异常移动构造
判断类型是否可以与自身无异常交换