Skip to content

Commit 74eb1d5

Browse files
committed
Fix std::optional variable is type
Current implementation for empty optional return true_type if types matches. After this fix type must match and optional needs to have a value.
1 parent b8649e9 commit 74eb1d5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/cpp2util.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,14 +1662,16 @@ auto as( X && x ) -> decltype(auto) {
16621662

16631663
// std::optional variable is Type
16641664
//
1665+
template<not_same_as<empty> T, specialization_of_template<std::optional> U>
1666+
requires not_same_as<T, U> && not_same_as<T, pointee_t<U>>
1667+
constexpr auto is( U&& x ) -> std::false_type {
1668+
return {};
1669+
}
1670+
16651671
template<not_same_as<empty> T, specialization_of_template<std::optional> U>
16661672
requires not_same_as<T, U>
16671673
constexpr auto is( U&& x ) {
1668-
if constexpr (same_type_as<T, pointee_t<U>>) {
1669-
return std::true_type{};
1670-
} else {
1671-
return std::false_type{};
1672-
}
1674+
return x.has_value();
16731675
}
16741676

16751677
//-------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)