MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
compressed_pair.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_UTILITY_COMPRESSED_PAIR_HPP__
2#define MSTL_CORE_UTILITY_COMPRESSED_PAIR_HPP__
3
11
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
34 T value{};
35
39 constexpr compressed_pair()
40 noexcept(is_nothrow_default_constructible_v<T>) = default;
41
46 constexpr compressed_pair(const compressed_pair& p)
47 noexcept(is_nothrow_copy_constructible_v<T>) : value(p.value) {}
48
55 noexcept(is_nothrow_copy_assignable_v<T>) {
56 value = _MSTL move(pir.value);
57 return *this;
58 }
59
65 noexcept(is_nothrow_move_constructible_v<T>) : value(_MSTL move(p.value)) {}
66
73 noexcept(is_nothrow_move_assignable_v<T>) {
74 value = _MSTL move(pir.value);
75 return *this;
76 }
77
85 template <typename... Args, enable_if_t<is_constructible_v<T, Args...>, int> = 0>
86 constexpr explicit compressed_pair(default_construct_tag, Args&&... args)
87 noexcept(conjunction_v<is_nothrow_default_constructible<IfEmpty>, is_nothrow_constructible<T, Args...>>)
88 : IfEmpty(), value(_MSTL forward<Args>(args)...) {}
89
99 template <typename ToEmpty, typename... Args, enable_if_t<conjunction_v<
101 constexpr explicit compressed_pair(exact_arg_construct_tag, ToEmpty&& first, Args&&... args)
102 noexcept(conjunction_v<is_nothrow_constructible<IfEmpty, ToEmpty>, is_nothrow_constructible<T, Args...>>)
103 : IfEmpty(_MSTL forward<ToEmpty>(first)), value(_MSTL forward<Args>(args)...) {}
104
109 constexpr compressed_pair& get_base() noexcept {
110 return *this;
111 }
112
117 constexpr const compressed_pair& get_base() const noexcept {
118 return *this;
119 }
120
125 constexpr void swap(compressed_pair& rhs)
126 noexcept(is_nothrow_swappable_v<T>) {
127 _MSTL swap(value, rhs.value);
128 }
129
134 constexpr size_t to_hash() const
135 noexcept(noexcept(hash<T>{}(value))) {
136 return hash<T>{}(value);
137 }
138
144 constexpr bool operator ==(const compressed_pair& y) const
145 noexcept(noexcept(this->value == y.value)) {
146 return this->value == y.value;
147 }
148
154 constexpr bool operator <(const compressed_pair& y) const
155 noexcept(noexcept(this->value < y.value)) {
156 return this->value < y.value;
157 }
158};
159
167template <typename IfEmpty, typename T>
171
175 constexpr compressed_pair()
176 noexcept(conjunction_v<
179 = default;
180
185 constexpr compressed_pair(const compressed_pair& pir)
186 noexcept(conjunction_v<
189 : no_compressed(pir.no_compressed), value(pir.value) {}
190
196 constexpr compressed_pair& operator =(const compressed_pair& pir)
197 noexcept(conjunction_v<
200 no_compressed = pir.no_compressed;
201 value = pir.value;
202 return *this;
203 }
204
214
220 constexpr compressed_pair& operator =(compressed_pair&& pir)
221 noexcept(conjunction_v<
224 no_compressed = _MSTL move(pir.no_compressed);
225 value = _MSTL move(pir.value);
226 return *this;
227 }
228
234 template <typename... Args>
235 constexpr explicit compressed_pair(default_construct_tag, Args&&... args)
236 noexcept(conjunction_v<
238 is_nothrow_constructible<T, Args...>>)
239 : no_compressed(), value(_MSTL forward<Args>(args)...) {}
240
248 template <typename ToEmpty, typename... Args>
249 constexpr compressed_pair(exact_arg_construct_tag, ToEmpty&& first, Args&&... args)
250 noexcept(conjunction_v<
252 is_nothrow_constructible<T, Args...>>)
253 : no_compressed(_MSTL forward<ToEmpty>(first)),
254 value(_MSTL forward<Args>(args)...) {}
255
260 constexpr IfEmpty& get_base() noexcept {
261 return no_compressed;
262 }
263
268 constexpr const IfEmpty& get_base() const noexcept {
269 return no_compressed;
270 }
271
276 constexpr void swap(compressed_pair& rhs)
277 noexcept(conjunction_v<is_nothrow_swappable<IfEmpty>, is_nothrow_swappable<T>>) {
278 _MSTL swap(value, rhs.value);
279 _MSTL swap(no_compressed, rhs.no_compressed);
280 }
281
286 constexpr size_t to_hash() const
287 noexcept(noexcept(hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value))) {
288 return hash<IfEmpty>{}(no_compressed) ^ hash<T>{}(value);
289 }
290
296 constexpr bool operator ==(const compressed_pair& y) const
297 noexcept(noexcept(this->no_compressed == y.no_compressed && this->value == y.value)) {
298 return this->no_compressed == y.no_compressed && this->value == y.value;
299 }
300
306 constexpr bool operator <(const compressed_pair& y) const
307 noexcept(noexcept(this->no_compressed < y.no_compressed || (!(y.no_compressed < this->no_compressed) && this->value < y.value))) {
308 return this->no_compressed < y.no_compressed || (!(y.no_compressed < this->no_compressed) && this->value < y.value);
309 }
310};
311
312
313#if MSTL_SUPPORT_DEDUCTION_GUIDES__
314template <typename IfEmpty, typename T>
316#endif
317 // CompressedPair
319
321#endif // MSTL_CORE_UTILITY_COMPRESSED_PAIR_HPP__
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
bool operator==(const function< Res(Args...)> &f, nullptr_t null) noexcept
等于空指针比较
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD constexpr bool operator<(const normal_iterator< LeftIter > &lhs, const normal_iterator< RightIter > &rhs) noexcept
小于比较运算符
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
void swap()=delete
删除无参数的swap重载
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
基本接口基类
constexpr const IfEmpty & get_base() const noexcept
获取基类常量引用
constexpr void swap(compressed_pair &rhs) noexcept(conjunction_v< is_nothrow_swappable< IfEmpty >, is_nothrow_swappable< 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... > >)
精确参数构造标签构造函数
IfEmpty no_compressed
未压缩的基类成员
constexpr IfEmpty & get_base() noexcept
获取基类引用
constexpr compressed_pair() noexcept(conjunction_v< is_nothrow_default_constructible< IfEmpty >, is_nothrow_default_constructible< T > >)=default
默认构造函数
压缩对主模板,使用EBCO优化
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=(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 size_t to_hash() const noexcept(noexcept(hash< T >{}(value)))
计算哈希值
constexpr compressed_pair() noexcept(is_nothrow_default_constructible_v< T >)=default
默认构造函数
默认构造标签
精确参数构造标签
哈希函数的主模板
通用接口,同时具备可比较和可哈希功能
判断类型是否可以使用指定参数构造
判断类型是否可以使用指定参数无异常构造
判断类型是否可无异常复制赋值
判断类型是否可无异常复制构造
判断类型是否可无异常默认构造
判断类型是否可无异常移动赋值
判断类型是否可无异常移动构造
判断类型是否可以与自身无异常交换