@@ -1856,40 +1856,38 @@ auto as( std::variant<Ts...> const& x ) -> decltype(auto) {
1856
1856
// std::any is and as
1857
1857
//
1858
1858
1859
- // is Type
1859
+ // std::any variable is Type
1860
1860
//
1861
- template <typename T, typename X>
1862
- requires (std::is_same_v<X,std::any> && !std::is_same_v<T,std::any> && !std::is_same_v<T,empty>)
1863
- constexpr auto is ( X const & x ) -> bool
1861
+ template <typename T>
1862
+ constexpr auto is ( same_type_as<std::any> auto && x ) -> bool
1864
1863
{ return x.type () == Typeid<T>(); }
1865
1864
1866
- template <typename T, typename X>
1867
- requires (std::is_same_v<X,std::any> && std::is_same_v<T,empty>)
1868
- constexpr auto is ( X const & x ) -> bool
1865
+ template <std::same_as<empty> T>
1866
+ constexpr auto is ( same_type_as<std::any> auto && x ) -> bool
1869
1867
{ return !x.has_value (); }
1870
1868
1871
1869
1872
- // is Value
1870
+ // std::any variable is Value
1873
1871
//
1874
- inline constexpr auto is ( std::any const & x, auto && value ) -> bool
1875
- {
1876
- // Predicate case
1877
- if constexpr (requires { bool { value (x) }; }) {
1878
- return value (x);
1879
- }
1880
- else if constexpr (std::is_function_v<decltype (value)> || requires { &value.operator (); }) {
1881
- return false ;
1882
- }
1883
1872
1884
- // Value case
1885
- else if constexpr (requires { bool { *std::any_cast<CPP2_TYPEOF (value)>(&x) == value }; }) {
1886
- auto pvalue = std::any_cast<CPP2_TYPEOF (value)>(&x);
1887
- return pvalue && *pvalue == value;
1888
- }
1889
- // else
1890
- return false ;
1873
+ template <std::same_as<std::any> X, has_defined_argument V>
1874
+ requires not_same_as<std::any, argument_of_t <V>>
1875
+ constexpr bool is ( X const & x, V && value ) {
1876
+ auto * ptr = std::any_cast<argument_of_t <V>>(&x);
1877
+ return ptr && value (*ptr);
1891
1878
}
1892
1879
1880
+ template <std::same_as<std::any> X, std::equality_comparable V>
1881
+ requires (!has_defined_argument<V>)
1882
+ constexpr bool is ( X const & x, V && value ) {
1883
+ if constexpr (pointer_like<V>) {
1884
+ auto * ptr = std::any_cast<pointee_t <V>>(&x);
1885
+ return ptr && !is<empty>(value) && is (*ptr, *value);
1886
+ } else {
1887
+ auto * ptr = std::any_cast<std::remove_cvref_t <V>>(&x);
1888
+ return ptr && is (*ptr, std::forward<V>(value));
1889
+ }
1890
+ }
1893
1891
1894
1892
// as
1895
1893
//
0 commit comments