@@ -1901,40 +1901,33 @@ constexpr auto as( X const& x ) -> T
1901
1901
// std::optional is and as
1902
1902
//
1903
1903
1904
- // is Type
1904
+ // std::optional variable is Type
1905
1905
//
1906
- template <typename T, typename X>
1907
- requires std::is_same_v<X,std::optional<T>>
1908
- constexpr auto is ( X const & x ) -> bool
1909
- { return x.has_value (); }
1910
-
1911
- template <typename T, typename U>
1912
- requires std::is_same_v<T,empty>
1913
- constexpr auto is ( std::optional<U> const & x ) -> bool
1914
- { return !x.has_value (); }
1906
+ template <not_same_as<empty> T, specialization_of_template<std::optional> U>
1907
+ requires not_same_as<T, U> && not_same_as<T, pointee_t <U>>
1908
+ constexpr auto is ( U&& ) -> std::false_type {
1909
+ return {};
1910
+ }
1915
1911
1912
+ template <not_same_as<empty> T, specialization_of_template<std::optional> U>
1913
+ requires not_same_as<T, U>
1914
+ constexpr auto is ( U&& x ) {
1915
+ return x.has_value ();
1916
+ }
1916
1917
1917
- // is Value
1918
+ // -------------------------------------------------------------------------------------------------------------
1919
+ // pointer_like variable is value
1918
1920
//
1919
- template <typename T>
1920
- constexpr auto is ( std::optional<T> const & x, auto && value ) -> bool
1921
- {
1922
- // Predicate case
1923
- if constexpr (requires{ bool { value (x) }; }) {
1924
- return value (x);
1925
- }
1926
- else if constexpr (std::is_function_v<decltype (value)> || requires{ &value.operator (); }) {
1927
- return false ;
1928
- }
1929
1921
1930
- // Value case
1931
- else if constexpr (requires{ bool { x.value () == value }; }) {
1932
- return x.has_value () && x.value () == value;
1922
+ template <pointer_like X, typename V>
1923
+ constexpr auto is ( X const & x, V && value) -> decltype(auto ) {
1924
+ if constexpr (pointer<X> && pointer<V>) {
1925
+ return x == value;
1926
+ } else {
1927
+ return !is<empty>(x) && is (*x, CPP2_FORWARD (value));
1933
1928
}
1934
- return false ;
1935
1929
}
1936
1930
1937
-
1938
1931
// as
1939
1932
//
1940
1933
template <typename T, typename X>
0 commit comments