@@ -205,6 +205,7 @@ namespace std {
205
205
# include < __type_traits/is_assignable.h>
206
206
# include < __type_traits/is_constructible.h>
207
207
# include < __type_traits/is_convertible.h>
208
+ # include < __type_traits/is_core_convertible.h>
208
209
# include < __type_traits/is_destructible.h>
209
210
# include < __type_traits/is_nothrow_assignable.h>
210
211
# include < __type_traits/is_nothrow_constructible.h>
@@ -982,11 +983,13 @@ public:
982
983
template <class _Tp >
983
984
optional (_Tp) -> optional<_Tp>;
984
985
985
- // Comparisons between optionals
986
+ // [optional.relops] Relational operators
987
+
986
988
template <
987
989
class _Tp ,
988
990
class _Up ,
989
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >, int > = 0 >
991
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >,
992
+ int > = 0 >
990
993
_LIBCPP_HIDE_FROM_ABI constexpr bool operator ==(const optional<_Tp>& __x, const optional<_Up>& __y) {
991
994
if (static_cast <bool >(__x) != static_cast <bool >(__y))
992
995
return false ;
@@ -998,7 +1001,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const
998
1001
template <
999
1002
class _Tp ,
1000
1003
class _Up ,
1001
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >, int > = 0 >
1004
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >,
1005
+ int > = 0 >
1002
1006
_LIBCPP_HIDE_FROM_ABI constexpr bool operator !=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1003
1007
if (static_cast <bool >(__x) != static_cast <bool >(__y))
1004
1008
return true ;
@@ -1007,10 +1011,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const
1007
1011
return *__x != *__y;
1008
1012
}
1009
1013
1010
- template <
1011
- class _Tp ,
1012
- class _Up ,
1013
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool >, int > = 0 >
1014
+ template < class _Tp ,
1015
+ class _Up ,
1016
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool > ,
1017
+ int > = 0 >
1014
1018
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <(const optional<_Tp>& __x, const optional<_Up>& __y) {
1015
1019
if (!static_cast <bool >(__y))
1016
1020
return false ;
@@ -1019,10 +1023,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const o
1019
1023
return *__x < *__y;
1020
1024
}
1021
1025
1022
- template <
1023
- class _Tp ,
1024
- class _Up ,
1025
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool >, int > = 0 >
1026
+ template < class _Tp ,
1027
+ class _Up ,
1028
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool > ,
1029
+ int > = 0 >
1026
1030
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >(const optional<_Tp>& __x, const optional<_Up>& __y) {
1027
1031
if (!static_cast <bool >(__x))
1028
1032
return false ;
@@ -1034,7 +1038,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const o
1034
1038
template <
1035
1039
class _Tp ,
1036
1040
class _Up ,
1037
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >, int > = 0 >
1041
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >,
1042
+ int > = 0 >
1038
1043
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1039
1044
if (!static_cast <bool >(__x))
1040
1045
return true ;
@@ -1046,7 +1051,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const
1046
1051
template <
1047
1052
class _Tp ,
1048
1053
class _Up ,
1049
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >, int > = 0 >
1054
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >,
1055
+ int > = 0 >
1050
1056
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >=(const optional<_Tp>& __x, const optional<_Up>& __y) {
1051
1057
if (!static_cast <bool >(__y))
1052
1058
return true ;
@@ -1067,7 +1073,8 @@ operator<=>(const optional<_Tp>& __x, const optional<_Up>& __y) {
1067
1073
1068
1074
# endif // _LIBCPP_STD_VER >= 20
1069
1075
1070
- // Comparisons with nullopt
1076
+ // [optional.nullops] Comparison with nullopt
1077
+
1071
1078
template <class _Tp >
1072
1079
_LIBCPP_HIDE_FROM_ABI constexpr bool operator ==(const optional<_Tp>& __x, nullopt_t ) noexcept {
1073
1080
return !static_cast <bool >(__x);
@@ -1139,99 +1146,108 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>&
1139
1146
1140
1147
# endif // _LIBCPP_STD_VER <= 17
1141
1148
1142
- // Comparisons with T
1149
+ // [optional.comp.with.t] Comparison with T
1150
+
1143
1151
template <
1144
1152
class _Tp ,
1145
1153
class _Up ,
1146
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >, int > = 0 >
1154
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >,
1155
+ int > = 0 >
1147
1156
_LIBCPP_HIDE_FROM_ABI constexpr bool operator ==(const optional<_Tp>& __x, const _Up& __v) {
1148
1157
return static_cast <bool >(__x) ? *__x == __v : false ;
1149
1158
}
1150
1159
1151
1160
template <
1152
1161
class _Tp ,
1153
1162
class _Up ,
1154
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >, int > = 0 >
1163
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() == std::declval<const _Up&>()), bool >,
1164
+ int > = 0 >
1155
1165
_LIBCPP_HIDE_FROM_ABI constexpr bool operator ==(const _Tp& __v, const optional<_Up>& __x) {
1156
1166
return static_cast <bool >(__x) ? __v == *__x : false ;
1157
1167
}
1158
1168
1159
1169
template <
1160
1170
class _Tp ,
1161
1171
class _Up ,
1162
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >, int > = 0 >
1172
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >,
1173
+ int > = 0 >
1163
1174
_LIBCPP_HIDE_FROM_ABI constexpr bool operator !=(const optional<_Tp>& __x, const _Up& __v) {
1164
1175
return static_cast <bool >(__x) ? *__x != __v : true ;
1165
1176
}
1166
1177
1167
1178
template <
1168
1179
class _Tp ,
1169
1180
class _Up ,
1170
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >, int > = 0 >
1181
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() != std::declval<const _Up&>()), bool >,
1182
+ int > = 0 >
1171
1183
_LIBCPP_HIDE_FROM_ABI constexpr bool operator !=(const _Tp& __v, const optional<_Up>& __x) {
1172
1184
return static_cast <bool >(__x) ? __v != *__x : true ;
1173
1185
}
1174
1186
1175
- template <
1176
- class _Tp ,
1177
- class _Up ,
1178
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool >, int > = 0 >
1187
+ template < class _Tp ,
1188
+ class _Up ,
1189
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool > ,
1190
+ int > = 0 >
1179
1191
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <(const optional<_Tp>& __x, const _Up& __v) {
1180
1192
return static_cast <bool >(__x) ? *__x < __v : true ;
1181
1193
}
1182
1194
1183
- template <
1184
- class _Tp ,
1185
- class _Up ,
1186
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool >, int > = 0 >
1195
+ template < class _Tp ,
1196
+ class _Up ,
1197
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() < std::declval< const _Up&>()), bool > ,
1198
+ int > = 0 >
1187
1199
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <(const _Tp& __v, const optional<_Up>& __x) {
1188
1200
return static_cast <bool >(__x) ? __v < *__x : false ;
1189
1201
}
1190
1202
1191
1203
template <
1192
1204
class _Tp ,
1193
1205
class _Up ,
1194
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >, int > = 0 >
1206
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >,
1207
+ int > = 0 >
1195
1208
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <=(const optional<_Tp>& __x, const _Up& __v) {
1196
1209
return static_cast <bool >(__x) ? *__x <= __v : true ;
1197
1210
}
1198
1211
1199
1212
template <
1200
1213
class _Tp ,
1201
1214
class _Up ,
1202
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >, int > = 0 >
1215
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() <= std::declval<const _Up&>()), bool >,
1216
+ int > = 0 >
1203
1217
_LIBCPP_HIDE_FROM_ABI constexpr bool operator <=(const _Tp& __v, const optional<_Up>& __x) {
1204
1218
return static_cast <bool >(__x) ? __v <= *__x : false ;
1205
1219
}
1206
1220
1207
- template <
1208
- class _Tp ,
1209
- class _Up ,
1210
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool >, int > = 0 >
1221
+ template < class _Tp ,
1222
+ class _Up ,
1223
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool > ,
1224
+ int > = 0 >
1211
1225
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >(const optional<_Tp>& __x, const _Up& __v) {
1212
1226
return static_cast <bool >(__x) ? *__x > __v : false ;
1213
1227
}
1214
1228
1215
- template <
1216
- class _Tp ,
1217
- class _Up ,
1218
- enable_if_t <is_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool >, int > = 0 >
1229
+ template < class _Tp ,
1230
+ class _Up ,
1231
+ enable_if_t <__is_core_convertible_v< decltype (std::declval< const _Tp&>() > std::declval< const _Up&>()), bool > ,
1232
+ int > = 0 >
1219
1233
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >(const _Tp& __v, const optional<_Up>& __x) {
1220
1234
return static_cast <bool >(__x) ? __v > *__x : true ;
1221
1235
}
1222
1236
1223
1237
template <
1224
1238
class _Tp ,
1225
1239
class _Up ,
1226
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >, int > = 0 >
1240
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >,
1241
+ int > = 0 >
1227
1242
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >=(const optional<_Tp>& __x, const _Up& __v) {
1228
1243
return static_cast <bool >(__x) ? *__x >= __v : false ;
1229
1244
}
1230
1245
1231
1246
template <
1232
1247
class _Tp ,
1233
1248
class _Up ,
1234
- enable_if_t <is_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >, int > = 0 >
1249
+ enable_if_t <__is_core_convertible_v<decltype (std::declval<const _Tp&>() >= std::declval<const _Up&>()), bool >,
1250
+ int > = 0 >
1235
1251
_LIBCPP_HIDE_FROM_ABI constexpr bool operator >=(const _Tp& __v, const optional<_Up>& __x) {
1236
1252
return static_cast <bool >(__x) ? __v >= *__x : true ;
1237
1253
}
0 commit comments