Advertisement
Guest User

Untitled

a guest
May 2nd, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.34 KB | None | 0 0
  1. diff --git a/libcxx/include/compare b/libcxx/include/compare
  2. index 4282a1e5fa80..c9d5e10db60e 100644
  3. --- a/libcxx/include/compare
  4. +++ b/libcxx/include/compare
  5. @@ -1,143 +1,139 @@
  6. // -*- C++ -*-
  7. //===-------------------------- compare -----------------------------------===//
  8. //
  9. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  10. // See https://llvm.org/LICENSE.txt for license information.
  11. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  12. //
  13. //===----------------------------------------------------------------------===//
  14.  
  15. #ifndef _LIBCPP_COMPARE
  16. #define _LIBCPP_COMPARE
  17.  
  18. /*
  19. compare synopsis
  20.  
  21. namespace std {
  22. // [cmp.categories], comparison category types
  23. class partial_ordering;
  24. class weak_ordering;
  25. class strong_ordering;
  26.  
  27. // named comparison functions
  28. - constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; }
  29. - constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
  30. constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
  31. constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
  32. constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
  33. constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
  34.  
  35. // [cmp.common], common comparison category type
  36. template<class... Ts>
  37. struct common_comparison_category {
  38. using type = see below;
  39. };
  40. template<class... Ts>
  41. using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
  42.  
  43. // [cmp.alg], comparison algorithms
  44. template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
  45. template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
  46. template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
  47. - template<class T> constexpr strong_equality strong_equal(const T& a, const T& b);
  48. - template<class T> constexpr weak_equality weak_equal(const T& a, const T& b);
  49.  
  50. // [cmp.partialord], Class partial_ordering
  51. class partial_ordering {
  52. public:
  53. // valid values
  54. static const partial_ordering less;
  55. static const partial_ordering equivalent;
  56. static const partial_ordering greater;
  57. static const partial_ordering unordered;
  58.  
  59. // comparisons
  60. friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
  61. friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
  62. friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
  63. friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
  64. friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
  65. friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
  66. friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
  67. friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
  68. friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
  69. friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
  70. friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
  71. friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
  72. };
  73.  
  74. // [cmp.weakord], Class weak_ordering
  75. class weak_ordering {
  76. public:
  77. // valid values
  78. static const weak_ordering less;
  79. static const weak_ordering equivalent;
  80. static const weak_ordering greater;
  81.  
  82. // conversions
  83. constexpr operator partial_ordering() const noexcept;
  84.  
  85. // comparisons
  86. friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
  87. friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
  88. friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
  89. friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
  90. friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
  91. friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
  92. friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
  93. friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
  94. friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
  95. friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
  96. friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
  97. friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
  98. };
  99.  
  100. // [cmp.strongord], Class strong_ordering
  101. class strong_ordering {
  102. public:
  103. // valid values
  104. static const strong_ordering less;
  105. static const strong_ordering equal;
  106. static const strong_ordering equivalent;
  107. static const strong_ordering greater;
  108.  
  109. // conversions
  110. constexpr operator partial_ordering() const noexcept;
  111. constexpr operator weak_ordering() const noexcept;
  112.  
  113. // comparisons
  114. friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
  115. friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
  116. friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
  117. friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
  118. friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
  119. friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
  120. friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
  121. friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
  122. friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
  123. friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
  124. friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
  125. friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
  126. };
  127. }
  128. */
  129.  
  130. #include <__config>
  131. #include <type_traits>
  132.  
  133. #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  134. #pragma GCC system_header
  135. #endif
  136.  
  137. _LIBCPP_BEGIN_NAMESPACE_STD
  138.  
  139. #if _LIBCPP_STD_VER > 17
  140.  
  141. // exposition only
  142. enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
  143. __zero = 0,
  144. __equal = __zero,
  145. __equiv = __equal,
  146. __nonequal = 1,
  147. __nonequiv = __nonequal
  148. };
  149. @@ -192,407 +188,403 @@ public:
  150. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
  151. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
  152. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  153. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  154. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  155. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  156. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  157. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  158.  
  159. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  160. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
  161.  
  162. _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
  163. _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
  164. #endif
  165.  
  166. private:
  167. _ValueT __value_;
  168. };
  169.  
  170. _LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
  171. _LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv);
  172. _LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
  173. _LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
  174.  
  175. _LIBCPP_INLINE_VISIBILITY
  176. constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  177. return __v.__is_ordered() && __v.__value_ == 0;
  178. }
  179. _LIBCPP_INLINE_VISIBILITY
  180. constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  181. return __v.__is_ordered() && __v.__value_ < 0;
  182. }
  183. _LIBCPP_INLINE_VISIBILITY
  184. constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  185. return __v.__is_ordered() && __v.__value_ <= 0;
  186. }
  187. _LIBCPP_INLINE_VISIBILITY
  188. constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  189. return __v.__is_ordered() && __v.__value_ > 0;
  190. }
  191. _LIBCPP_INLINE_VISIBILITY
  192. constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  193. return __v.__is_ordered() && __v.__value_ >= 0;
  194. }
  195.  
  196. _LIBCPP_INLINE_VISIBILITY
  197. constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  198. return __v.__is_ordered() && 0 == __v.__value_;
  199. }
  200. _LIBCPP_INLINE_VISIBILITY
  201. constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  202. return __v.__is_ordered() && 0 < __v.__value_;
  203. }
  204. _LIBCPP_INLINE_VISIBILITY
  205. constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  206. return __v.__is_ordered() && 0 <= __v.__value_;
  207. }
  208. _LIBCPP_INLINE_VISIBILITY
  209. constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  210. return __v.__is_ordered() && 0 > __v.__value_;
  211. }
  212. _LIBCPP_INLINE_VISIBILITY
  213. constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  214. return __v.__is_ordered() && 0 >= __v.__value_;
  215. }
  216.  
  217. _LIBCPP_INLINE_VISIBILITY
  218. constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  219. return !__v.__is_ordered() || __v.__value_ != 0;
  220. }
  221. _LIBCPP_INLINE_VISIBILITY
  222. constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  223. return !__v.__is_ordered() || __v.__value_ != 0;
  224. }
  225.  
  226. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  227. _LIBCPP_INLINE_VISIBILITY
  228. constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
  229. return __v;
  230. }
  231. _LIBCPP_INLINE_VISIBILITY
  232. constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
  233. return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
  234. }
  235. #endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  236.  
  237. class weak_ordering {
  238. using _ValueT = signed char;
  239.  
  240. _LIBCPP_INLINE_VISIBILITY
  241. explicit constexpr weak_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
  242. _LIBCPP_INLINE_VISIBILITY
  243. explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
  244.  
  245. public:
  246. static const weak_ordering less;
  247. static const weak_ordering equivalent;
  248. static const weak_ordering greater;
  249.  
  250. - // conversions
  251. _LIBCPP_INLINE_VISIBILITY
  252. constexpr operator partial_ordering() const noexcept {
  253. return __value_ == 0 ? partial_ordering::equivalent
  254. : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
  255. }
  256.  
  257. // comparisons
  258. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  259. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  260. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  261. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  262. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  263. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  264. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  265. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  266. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  267. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  268. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  269. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  270.  
  271. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  272. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
  273.  
  274. _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
  275. _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
  276. #endif
  277.  
  278. private:
  279. _ValueT __value_;
  280. };
  281.  
  282. _LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
  283. _LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::equivalent(_EqResult::__equiv);
  284. _LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
  285.  
  286. _LIBCPP_INLINE_VISIBILITY
  287. constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  288. return __v.__value_ == 0;
  289. }
  290. _LIBCPP_INLINE_VISIBILITY
  291. constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  292. return __v.__value_ != 0;
  293. }
  294. _LIBCPP_INLINE_VISIBILITY
  295. constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  296. return __v.__value_ < 0;
  297. }
  298. _LIBCPP_INLINE_VISIBILITY
  299. constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  300. return __v.__value_ <= 0;
  301. }
  302. _LIBCPP_INLINE_VISIBILITY
  303. constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  304. return __v.__value_ > 0;
  305. }
  306. _LIBCPP_INLINE_VISIBILITY
  307. constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  308. return __v.__value_ >= 0;
  309. }
  310. _LIBCPP_INLINE_VISIBILITY
  311. constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  312. return 0 == __v.__value_;
  313. }
  314. _LIBCPP_INLINE_VISIBILITY
  315. constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  316. return 0 != __v.__value_;
  317. }
  318. _LIBCPP_INLINE_VISIBILITY
  319. constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  320. return 0 < __v.__value_;
  321. }
  322. _LIBCPP_INLINE_VISIBILITY
  323. constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  324. return 0 <= __v.__value_;
  325. }
  326. _LIBCPP_INLINE_VISIBILITY
  327. constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  328. return 0 > __v.__value_;
  329. }
  330. _LIBCPP_INLINE_VISIBILITY
  331. constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  332. return 0 >= __v.__value_;
  333. }
  334.  
  335. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  336. _LIBCPP_INLINE_VISIBILITY
  337. constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
  338. return __v;
  339. }
  340. _LIBCPP_INLINE_VISIBILITY
  341. constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
  342. return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
  343. }
  344. #endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  345.  
  346. class strong_ordering {
  347. using _ValueT = signed char;
  348.  
  349. _LIBCPP_INLINE_VISIBILITY
  350. explicit constexpr strong_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
  351. _LIBCPP_INLINE_VISIBILITY
  352. explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
  353.  
  354. public:
  355. static const strong_ordering less;
  356. static const strong_ordering equal;
  357. static const strong_ordering equivalent;
  358. static const strong_ordering greater;
  359.  
  360. - // conversions
  361. _LIBCPP_INLINE_VISIBILITY
  362. constexpr operator partial_ordering() const noexcept {
  363. return __value_ == 0 ? partial_ordering::equivalent
  364. : (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
  365. }
  366.  
  367. _LIBCPP_INLINE_VISIBILITY
  368. constexpr operator weak_ordering() const noexcept {
  369. return __value_ == 0 ? weak_ordering::equivalent
  370. : (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
  371. }
  372.  
  373. // comparisons
  374. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  375. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  376. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  377. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  378. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  379. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  380. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  381. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  382. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  383. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  384. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  385. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  386.  
  387. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  388. _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
  389.  
  390. _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
  391. _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
  392. #endif
  393.  
  394. private:
  395. _ValueT __value_;
  396. };
  397.  
  398. _LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
  399. _LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equal(_EqResult::__equal);
  400. _LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equivalent(_EqResult::__equiv);
  401. _LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
  402.  
  403. _LIBCPP_INLINE_VISIBILITY
  404. constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  405. return __v.__value_ == 0;
  406. }
  407. _LIBCPP_INLINE_VISIBILITY
  408. constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  409. return __v.__value_ != 0;
  410. }
  411. _LIBCPP_INLINE_VISIBILITY
  412. constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  413. return __v.__value_ < 0;
  414. }
  415. _LIBCPP_INLINE_VISIBILITY
  416. constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  417. return __v.__value_ <= 0;
  418. }
  419. _LIBCPP_INLINE_VISIBILITY
  420. constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  421. return __v.__value_ > 0;
  422. }
  423. _LIBCPP_INLINE_VISIBILITY
  424. constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  425. return __v.__value_ >= 0;
  426. }
  427. _LIBCPP_INLINE_VISIBILITY
  428. constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  429. return 0 == __v.__value_;
  430. }
  431. _LIBCPP_INLINE_VISIBILITY
  432. constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  433. return 0 != __v.__value_;
  434. }
  435. _LIBCPP_INLINE_VISIBILITY
  436. constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  437. return 0 < __v.__value_;
  438. }
  439. _LIBCPP_INLINE_VISIBILITY
  440. constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  441. return 0 <= __v.__value_;
  442. }
  443. _LIBCPP_INLINE_VISIBILITY
  444. constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  445. return 0 > __v.__value_;
  446. }
  447. _LIBCPP_INLINE_VISIBILITY
  448. constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  449. return 0 >= __v.__value_;
  450. }
  451.  
  452. #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  453. _LIBCPP_INLINE_VISIBILITY
  454. constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
  455. return __v;
  456. }
  457. _LIBCPP_INLINE_VISIBILITY
  458. constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
  459. return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
  460. }
  461. #endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
  462.  
  463. // named comparison functions
  464. -_LIBCPP_INLINE_VISIBILITY
  465. -constexpr bool is_eq(partial_ordering __cmp) noexcept { return __cmp == 0; }
  466. -
  467. -_LIBCPP_INLINE_VISIBILITY
  468. -constexpr bool is_neq(partial_ordering __cmp) noexcept { return __cmp != 0; }
  469. -
  470. _LIBCPP_INLINE_VISIBILITY
  471. constexpr bool is_lt(partial_ordering __cmp) noexcept { return __cmp < 0; }
  472.  
  473. _LIBCPP_INLINE_VISIBILITY
  474. constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; }
  475.  
  476. _LIBCPP_INLINE_VISIBILITY
  477. constexpr bool is_gt(partial_ordering __cmp) noexcept { return __cmp > 0; }
  478.  
  479. _LIBCPP_INLINE_VISIBILITY
  480. constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; }
  481.  
  482. namespace __comp_detail {
  483.  
  484. enum _ClassifyCompCategory : unsigned{
  485. _None,
  486. + _WeakEq,
  487. + _StrongEq,
  488. _PartialOrd,
  489. _WeakOrd,
  490. _StrongOrd,
  491. _CCC_Size
  492. };
  493.  
  494. template <class _Tp>
  495. _LIBCPP_INLINE_VISIBILITY
  496. constexpr _ClassifyCompCategory __type_to_enum() noexcept {
  497. if (is_same_v<_Tp, partial_ordering>)
  498. return _PartialOrd;
  499. if (is_same_v<_Tp, weak_ordering>)
  500. return _WeakOrd;
  501. if (is_same_v<_Tp, strong_ordering>)
  502. return _StrongOrd;
  503. return _None;
  504. }
  505.  
  506. template <size_t _Size>
  507. constexpr _ClassifyCompCategory
  508. __compute_comp_type(const _ClassifyCompCategory (&__types)[_Size]) {
  509. int __seen[_CCC_Size] = {};
  510. for (auto __type : __types)
  511. ++__seen[__type];
  512. if (__seen[_None])
  513. return _None;
  514. + if (__seen[_WeakEq])
  515. + return _WeakEq;
  516. + if (__seen[_StrongEq] && (__seen[_PartialOrd] || __seen[_WeakOrd]))
  517. + return _WeakEq;
  518. + if (__seen[_StrongEq])
  519. + return _StrongEq;
  520. if (__seen[_PartialOrd])
  521. return _PartialOrd;
  522. if (__seen[_WeakOrd])
  523. return _WeakOrd;
  524. return _StrongOrd;
  525. }
  526.  
  527. template <class ..._Ts>
  528. constexpr auto __get_comp_type() {
  529. using _CCC = _ClassifyCompCategory;
  530. constexpr _CCC __type_kinds[] = {_StrongOrd, __type_to_enum<_Ts>()...};
  531. constexpr _CCC _Cat = __compute_comp_type(__type_kinds);
  532. - if constexpr (_Cat == _None)
  533. - return void();
  534. - else if constexpr (_Cat == _PartialOrd)
  535. + if constexpr (_Cat == _PartialOrd)
  536. return partial_ordering::equivalent;
  537. else if constexpr (_Cat == _WeakOrd)
  538. return weak_ordering::equivalent;
  539. - else if constexpr (_Cat == _StrongOrd)
  540. - return strong_ordering::equivalent;
  541. else
  542. - static_assert(_Cat != _Cat, "unhandled case");
  543. + return strong_ordering::equivalent;
  544. }
  545. } // namespace __comp_detail
  546.  
  547. // [cmp.common], common comparison category type
  548. template<class... _Ts>
  549. struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
  550. using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
  551. };
  552.  
  553. template<class... _Ts>
  554. using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
  555.  
  556. // [cmp.alg], comparison algorithms
  557. // TODO: unimplemented
  558. template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
  559. template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
  560. template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
  561.  
  562. #endif // _LIBCPP_STD_VER > 17
  563.  
  564. _LIBCPP_END_NAMESPACE_STD
  565.  
  566. #endif // _LIBCPP_COMPARE
  567. diff --git a/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp
  568. index 70ee429685b7..3e1f43a069a6 100644
  569. --- a/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp
  570. +++ b/libcxx/test/std/language.support/cmp/cmp.common/common_comparison_category.pass.cpp
  571. @@ -1,75 +1,65 @@
  572. //===----------------------------------------------------------------------===//
  573. //
  574. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  575. // See https://llvm.org/LICENSE.txt for license information.
  576. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  577. //
  578. //===----------------------------------------------------------------------===//
  579.  
  580. // UNSUPPORTED: c++03, c++11, c++14, c++17
  581.  
  582. // <compare>
  583.  
  584. // template <class ...Ts> struct common_comparison_category
  585. // template <class ...Ts> using common_comparison_category_t
  586.  
  587.  
  588. #include <compare>
  589. #include <type_traits>
  590. #include <cassert>
  591.  
  592. #include "test_macros.h"
  593.  
  594. const volatile void* volatile sink;
  595.  
  596. template <class Expect, class ...Args>
  597. void test_cat() {
  598. using Cat = std::common_comparison_category<Args...>;
  599. using CatT = typename Cat::type;
  600. static_assert(std::is_same<CatT, std::common_comparison_category_t<Args...>>::value, "");
  601. static_assert(std::is_same<CatT, Expect>::value, "expected different category");
  602. };
  603.  
  604.  
  605. // [class.spaceship]p4: The 'common comparison type' U of a possibly-empty list
  606. // of 'n' types T0, T1, ..., TN, is defined as follows:
  607. int main(int, char**) {
  608. using PO = std::partial_ordering;
  609. using WO = std::weak_ordering;
  610. using SO = std::strong_ordering;
  611.  
  612. - // [class.spaceship]p4.1: If any Ti is not a comparison category tpe, U is void.
  613. - {
  614. - test_cat<void, void>();
  615. - test_cat<void, int*>();
  616. - test_cat<void, SO&>();
  617. - test_cat<void, SO const>();
  618. - test_cat<void, SO*>();
  619. - test_cat<void, SO, void, SO>();
  620. - }
  621. -
  622. - // [class.spaceship]p4.2: Otherwise, if at least one Ti is std::partial_ordering,
  623. - // U is std::partial_ordering
  624. + // [class.spaceship]p4.1: If at least one Ti is std::partial_ordering, U is
  625. + // std::partial_ordering ([cmp.partialord]).
  626. {
  627. test_cat<PO, PO>();
  628. test_cat<PO, SO, PO, SO>();
  629. test_cat<PO, WO, PO, SO>();
  630. }
  631.  
  632. - // [class.spaceship]p4.3: Otherwise, if at least one Ti is std::weak_ordering,
  633. + // [class.spaceship]p4.2: Otherwise, if at least one Ti is std::weak_ordering,
  634. // U is std::weak_ordering
  635. {
  636. test_cat<WO, WO>();
  637. test_cat<WO, SO, WO, SO>();
  638. }
  639.  
  640. - // [class.spaceship]p4.4: Otherwise, U is std::strong_ordering. [Note: in
  641. + // [class.spaceship]p4.3: Otherwise, U is std::strong_ordering. [Note: in
  642. // particular this is the result when n is 0. -- end note]
  643. {
  644. test_cat<SO>(); // empty type list
  645. test_cat<SO, SO>();
  646. test_cat<SO, SO, SO>();
  647. }
  648.  
  649. return 0;
  650. }
  651. diff --git a/libcxx/test/std/language.support/cmp/cmp.strongeq/cmp.strongeq.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.strongeq/cmp.strongeq.pass.cpp
  652. deleted file mode 100644
  653. index 368a1a436936..000000000000
  654. --- a/libcxx/test/std/language.support/cmp/cmp.strongeq/cmp.strongeq.pass.cpp
  655. +++ /dev/null
  656. @@ -1,97 +0,0 @@
  657. -//===----------------------------------------------------------------------===//
  658. -//
  659. -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  660. -// See https://llvm.org/LICENSE.txt for license information.
  661. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  662. -//
  663. -//===----------------------------------------------------------------------===//
  664. -
  665. -// UNSUPPORTED: c++03, c++11, c++14, c++17
  666. -
  667. -// <compare>
  668. -
  669. -// class strong_equality
  670. -
  671. -
  672. -#include <compare>
  673. -#include <type_traits>
  674. -#include <cassert>
  675. -
  676. -#include "test_macros.h"
  677. -
  678. -const volatile void* volatile sink;
  679. -
  680. -void test_static_members() {
  681. - DoNotOptimize(&std::strong_equality::equal);
  682. - DoNotOptimize(&std::strong_equality::nonequal);
  683. - DoNotOptimize(&std::strong_equality::equivalent);
  684. - DoNotOptimize(&std::strong_equality::nonequivalent);
  685. -}
  686. -
  687. -void test_signatures() {
  688. - auto& Eq = std::strong_equality::equivalent;
  689. -
  690. - ASSERT_NOEXCEPT(Eq == 0);
  691. - ASSERT_NOEXCEPT(0 == Eq);
  692. - ASSERT_NOEXCEPT(Eq != 0);
  693. - ASSERT_NOEXCEPT(0 != Eq);
  694. -#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  695. - ASSERT_NOEXCEPT(0 <=> Eq);
  696. - ASSERT_NOEXCEPT(Eq <=> 0);
  697. - ASSERT_SAME_TYPE(decltype(Eq <=> 0), std::strong_equality);
  698. - ASSERT_SAME_TYPE(decltype(0 <=> Eq), std::strong_equality);
  699. -#endif
  700. -}
  701. -
  702. -void test_conversion() {
  703. - constexpr std::weak_equality res = std::strong_equality::equivalent;
  704. - static_assert(res == 0, "");
  705. - static_assert(std::is_convertible<const std::strong_equality&,
  706. - std::weak_equality>::value, "");
  707. - static_assert(res == 0, "expected equal");
  708. -
  709. - constexpr std::weak_equality neq_res = std::strong_equality::nonequivalent;
  710. - static_assert(neq_res != 0, "expected not equal");
  711. -}
  712. -
  713. -constexpr bool test_constexpr() {
  714. - auto& Eq = std::strong_equality::equal;
  715. - auto& NEq = std::strong_equality::nonequal;
  716. - auto& Equiv = std::strong_equality::equivalent;
  717. - auto& NEquiv = std::strong_equality::nonequivalent;
  718. - assert((Eq == 0) == true);
  719. - assert((0 == Eq) == true);
  720. - assert((Equiv == 0) == true);
  721. - assert((0 == Equiv) == true);
  722. - assert((NEq == 0) == false);
  723. - assert((0 == NEq) == false);
  724. - assert((NEquiv == 0) == false);
  725. - assert((0 == NEquiv) == false);
  726. -
  727. - assert((Eq != 0) == false);
  728. - assert((0 != Eq) == false);
  729. - assert((Equiv != 0) == false);
  730. - assert((0 != Equiv) == false);
  731. - assert((NEq != 0) == true);
  732. - assert((0 != NEq) == true);
  733. - assert((NEquiv != 0) == true);
  734. - assert((0 != NEquiv) == true);
  735. -
  736. -#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  737. - std::strong_equality res = (Eq <=> 0);
  738. - ((void)res);
  739. - res = (0 <=> Eq);
  740. - ((void)res);
  741. -#endif
  742. -
  743. - return true;
  744. -}
  745. -
  746. -int main(int, char**) {
  747. - test_static_members();
  748. - test_signatures();
  749. - test_conversion();
  750. - static_assert(test_constexpr(), "constexpr test failed");
  751. -
  752. - return 0;
  753. -}
  754. diff --git a/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp
  755. deleted file mode 100644
  756. index 0d947ec53212..000000000000
  757. --- a/libcxx/test/std/language.support/cmp/cmp.weakeq/cmp.weakeq.pass.cpp
  758. +++ /dev/null
  759. @@ -1,71 +0,0 @@
  760. -//===----------------------------------------------------------------------===//
  761. -//
  762. -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  763. -// See https://llvm.org/LICENSE.txt for license information.
  764. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  765. -//
  766. -//===----------------------------------------------------------------------===//
  767. -
  768. -// UNSUPPORTED: c++03, c++11, c++14, c++17
  769. -
  770. -// <compare>
  771. -
  772. -// class weak_equality
  773. -
  774. -
  775. -#include <compare>
  776. -#include <cassert>
  777. -#include "test_macros.h"
  778. -
  779. -const volatile void* volatile sink;
  780. -
  781. -void test_static_members() {
  782. - DoNotOptimize(&std::weak_equality::equivalent);
  783. - DoNotOptimize(&std::weak_equality::nonequivalent);
  784. -}
  785. -
  786. -void test_signatures() {
  787. - auto& Eq = std::weak_equality::equivalent;
  788. -
  789. - ASSERT_NOEXCEPT(Eq == 0);
  790. - ASSERT_NOEXCEPT(0 == Eq);
  791. - ASSERT_NOEXCEPT(Eq != 0);
  792. - ASSERT_NOEXCEPT(0 != Eq);
  793. -#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  794. - ASSERT_NOEXCEPT(0 <=> Eq);
  795. - ASSERT_NOEXCEPT(Eq <=> 0);
  796. - ASSERT_SAME_TYPE(decltype(Eq <=> 0), std::weak_equality);
  797. - ASSERT_SAME_TYPE(decltype(0 <=> Eq), std::weak_equality);
  798. -#endif
  799. -}
  800. -
  801. -constexpr bool test_constexpr() {
  802. - auto& Eq = std::weak_equality::equivalent;
  803. - auto& NEq = std::weak_equality::nonequivalent;
  804. - assert((Eq == 0) == true);
  805. - assert((0 == Eq) == true);
  806. - assert((NEq == 0) == false);
  807. - assert((0 == NEq) == false);
  808. -
  809. - assert((Eq != 0) == false);
  810. - assert((0 != Eq) == false);
  811. - assert((NEq != 0) == true);
  812. - assert((0 != NEq) == true);
  813. -
  814. -#ifndef TEST_HAS_NO_SPACESHIP_OPERATOR
  815. - std::weak_equality res = (Eq <=> 0);
  816. - ((void)res);
  817. - res = (0 <=> Eq);
  818. - ((void)res);
  819. -#endif
  820. -
  821. - return true;
  822. -}
  823. -
  824. -int main(int, char**) {
  825. - test_static_members();
  826. - test_signatures();
  827. - static_assert(test_constexpr(), "constexpr test failed");
  828. -
  829. - return 0;
  830. -}
  831.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement