diff --git a/strings/base_array.h b/strings/base_array.h index 3b46f26a9..46c1fbdbf 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -71,18 +71,20 @@ WINRT_EXPORT namespace winrt {} template - array_view(array_view const& other, - std::enable_if_t, int> = 0) noexcept : + requires std::convertible_to + array_view(array_view const& other) noexcept : array_view(other.data(), other.size()) {} - template , std::remove_cv_t>, int> = 0> + template + requires std::same_as, std::remove_cv_t> bool operator==(array_view const& right) const noexcept { return std::equal(begin(), end(), right.begin(), right.end()); } - template , std::remove_cv_t>, int> = 0> + template + requires std::same_as, std::remove_cv_t> std::weak_ordering operator<=>(array_view const& right) const noexcept { return std::lexicographical_compare_three_way(begin(), end(), right.begin(), right.end()); @@ -284,7 +286,8 @@ WINRT_EXPORT namespace winrt std::uninitialized_fill_n(this->m_data, count, value); } - template ::difference_type>> + template + requires std::input_iterator com_array(InIt first, InIt last) { alloc(static_cast(std::distance(first, last))); @@ -317,7 +320,8 @@ WINRT_EXPORT namespace winrt com_array(value.begin(), value.end()) {} - template >> + template + requires std::convertible_to com_array(std::initializer_list value) : com_array(value.begin(), value.end()) {} @@ -402,7 +406,8 @@ WINRT_EXPORT namespace winrt }; template com_array(std::uint32_t, C const&) -> com_array>; - template ::difference_type>> + template + requires std::input_iterator com_array(InIt, InIt) -> com_array::value_type>>; template com_array(std::vector const&) -> com_array>; template com_array(std::array const&) -> com_array>; diff --git a/strings/base_collections_base.h b/strings/base_collections_base.h index d299cc0c8..6c31fe5a6 100644 --- a/strings/base_collections_base.h +++ b/strings/base_collections_base.h @@ -46,7 +46,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct removed_values::value_type>>> + requires (!std::is_trivially_destructible_v::value_type>) + struct removed_values { container_type_t m_value; @@ -65,7 +66,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct removed_value && !std::is_trivially_destructible_v>> + requires (std::is_move_constructible_v && !std::is_trivially_destructible_v) + struct removed_value { std::optional m_value; diff --git a/strings/base_collections_input_iterable.h b/strings/base_collections_input_iterable.h index e9d3af251..f3e503103 100644 --- a/strings/base_collections_input_iterable.h +++ b/strings/base_collections_input_iterable.h @@ -92,7 +92,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_pair.first, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to iterable(Collection const& values) noexcept { m_pair.first = values; @@ -112,7 +113,8 @@ WINRT_EXPORT namespace winrt::param { } - template , int> = 0> + template + requires std::convertible_to iterable(std::initializer_list values) : m_pair(impl::make_scoped_input_iterable(values.begin(), values.end())) { } @@ -164,7 +166,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_pair.first, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to iterable(Collection const& values) noexcept { m_pair.first = values; @@ -247,7 +250,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to async_iterable(Collection const& values) noexcept { m_interface = values; @@ -301,7 +305,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to async_iterable(Collection const& values) noexcept { m_interface = values; diff --git a/strings/base_collections_input_map.h b/strings/base_collections_input_map.h index 3fe146bf6..651662e1d 100644 --- a/strings/base_collections_input_map.h +++ b/strings/base_collections_input_map.h @@ -61,7 +61,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to map(Collection const& values) noexcept { m_interface = values; diff --git a/strings/base_collections_input_map_view.h b/strings/base_collections_input_map_view.h index d79eed61d..eb7be25fc 100644 --- a/strings/base_collections_input_map_view.h +++ b/strings/base_collections_input_map_view.h @@ -91,7 +91,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_pair.first, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to map_view(Collection const& values) noexcept { m_pair.first = values; @@ -169,7 +170,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to async_map_view(Collection const& values) noexcept { m_interface = values; diff --git a/strings/base_collections_input_vector.h b/strings/base_collections_input_vector.h index a06e73b33..049b23754 100644 --- a/strings/base_collections_input_vector.h +++ b/strings/base_collections_input_vector.h @@ -55,7 +55,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to vector(Collection const& values) noexcept { m_interface = values; diff --git a/strings/base_collections_input_vector_view.h b/strings/base_collections_input_vector_view.h index 30768c18e..d24a5b6db 100644 --- a/strings/base_collections_input_vector_view.h +++ b/strings/base_collections_input_vector_view.h @@ -86,7 +86,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_pair.first, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to vector_view(Collection const& values) noexcept { m_pair.first = values; @@ -106,7 +107,8 @@ WINRT_EXPORT namespace winrt::param { } - template , int> = 0> + template + requires std::convertible_to vector_view(std::initializer_list values) : m_pair(impl::make_scoped_input_vector_view(values.begin(), values.end())) { } @@ -164,7 +166,8 @@ WINRT_EXPORT namespace winrt::param attach_abi(m_interface, winrt::get_abi(values)); } - template , int> = 0> + template + requires std::convertible_to async_vector_view(Collection const& values) noexcept { m_interface = values; diff --git a/strings/base_com_ptr.h b/strings/base_com_ptr.h index c82323988..1925bf5df 100644 --- a/strings/base_com_ptr.h +++ b/strings/base_com_ptr.h @@ -24,7 +24,8 @@ WINRT_EXPORT namespace winrt::impl return function(args..., guid_of(), capture_decay{ result }); } - template || std::is_union_v, int> = 0> + template + requires (std::is_class_v || std::is_union_v) std::int32_t capture_to(void** result, O* object, M method, Args&& ...args) { return (object->*method)(args..., guid_of(), capture_decay{ result }); diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index d242d2a1a..1252a4e05 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -259,7 +259,8 @@ WINRT_EXPORT namespace winrt::impl WINRT_EXPORT namespace winrt { - template>> + template + requires std::convertible_to inline impl::await_adapter, false> resume_agile(Async&& async) { return { std::forward(async) }; diff --git a/strings/base_implements.h b/strings/base_implements.h index 302656cc5..8b4e6c209 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -145,14 +145,15 @@ WINRT_EXPORT namespace winrt::impl template struct root_implements; - template > + template struct unwrap_implements { using type = T; }; template - struct unwrap_implements> + requires requires { typename T::implements_type; } + struct unwrap_implements { using type = typename T::implements_type; }; @@ -173,28 +174,31 @@ WINRT_EXPORT namespace winrt::impl "Duplicate nested implements found"); }; - template , typename... I> + template struct base_implements_impl : impl::identity> {}; template - struct base_implements_impl::type>, I...> + requires requires { typename nested_implements::type; } + struct base_implements_impl : nested_implements {}; template using base_implements = base_implements_impl; - template > + template struct has_composable : std::false_type {}; template - struct has_composable> : std::true_type {}; + requires requires { typename T::composable; } + struct has_composable : std::true_type {}; - template > + template struct has_class_type : std::false_type {}; template - struct has_class_type> : std::true_type {}; + requires requires { typename T::class_type; } + struct has_class_type : std::true_type {}; template struct has_static_lifetime : std::false_type {}; @@ -367,20 +371,22 @@ WINRT_EXPORT namespace winrt::impl static constexpr std::array value{ winrt::guid_of() ... }; }; - template + template struct implements_default_interface { using type = typename default_interface::first_interface>::type; }; template - struct implements_default_interface> + requires requires { typename T::class_type; } + struct implements_default_interface { using type = winrt::default_interface; }; template - struct default_interface> + requires requires { typename T::implements_type; } + struct default_interface { using type = typename implements_default_interface::type; }; @@ -480,7 +486,7 @@ WINRT_EXPORT namespace winrt::impl } } - template > + template struct runtime_class_name { static hstring get() @@ -490,7 +496,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct runtime_class_name)>> + requires requires { name_v; } + struct runtime_class_name { static hstring get() { @@ -554,7 +561,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct producer::value>> : I + requires is_classic_com_interface::value + struct producer : I { #ifndef WINRT_IMPL_IUNKNOWN_DEFINED static_assert(std::is_void_v /* dependent_false */, "To implement classic COM interfaces, you must #include before including C++/WinRT headers."); @@ -562,7 +570,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct producer_convert::value>> : producer + requires is_classic_com_interface::value + struct producer_convert : producer { }; diff --git a/strings/base_includes.h b/strings/base_includes.h index 56e27e109..eb347d405 100644 --- a/strings/base_includes.h +++ b/strings/base_includes.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/strings/base_iterator.h b/strings/base_iterator.h index e6670327d..9cc37252a 100644 --- a/strings/base_iterator.h +++ b/strings/base_iterator.h @@ -120,7 +120,8 @@ WINRT_EXPORT namespace winrt::impl static constexpr bool value = get_value(0); }; - template ::value, int> = 0> + template + requires (!has_GetAt::value) auto get_begin_iterator(T const& collection) -> decltype(collection.First()) { auto result = collection.First(); @@ -133,31 +134,36 @@ WINRT_EXPORT namespace winrt::impl return result; } - template ::value, int> = 0> + template + requires (!has_GetAt::value) auto get_end_iterator([[maybe_unused]] T const& collection) noexcept -> decltype(collection.First()) { return {}; } - template ::value, int> = 0> + template + requires has_GetAt::value fast_iterator get_begin_iterator(T const& collection) noexcept { return { collection, 0 }; } - template ::value, int> = 0> + template + requires has_GetAt::value fast_iterator get_end_iterator(T const& collection) { return { collection, collection.Size() }; } - template ::value, int> = 0> + template + requires has_GetAt::value auto rbegin(T const& collection) { return std::make_reverse_iterator(get_end_iterator(collection)); } - template ::value, int> = 0> + template + requires has_GetAt::value auto rend(T const& collection) { return std::make_reverse_iterator(get_begin_iterator(collection)); diff --git a/strings/base_meta.h b/strings/base_meta.h index 6b28640ef..f3da5c73a 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -68,7 +68,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct abi>> + requires std::is_enum_v + struct abi { using type = std::underlying_type_t; }; @@ -85,7 +86,7 @@ WINRT_EXPORT namespace winrt::impl template struct delegate; - template > + template struct default_interface { using type = T; @@ -149,11 +150,12 @@ WINRT_EXPORT namespace winrt::impl return static_cast>(value); } - template > + template struct is_implements : std::false_type {}; template - struct is_implements> : std::true_type {}; + requires requires { typename T::implements_type; } + struct is_implements : std::true_type {}; template inline constexpr bool is_implements_v = is_implements::value; @@ -223,7 +225,8 @@ WINRT_EXPORT namespace winrt::impl }; template - struct arg>> + requires std::is_base_of_v + struct arg { using in = void*; }; diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 454ac4b2c..b3941a45b 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -480,7 +480,8 @@ WINRT_EXPORT namespace winrt::impl return default_value; } - template , int>> + template + requires (!is_com_interface_v) auto as(From* ptr) { if constexpr (impl::is_com_interface_v) @@ -493,7 +494,8 @@ WINRT_EXPORT namespace winrt::impl } } - template , int>> + template + requires (!is_com_interface_v) auto try_as(From* ptr) noexcept { using type = std::conditional_t, Windows::Foundation::IUnknown, com_ptr>; @@ -508,7 +510,8 @@ WINRT_EXPORT namespace winrt return Windows::Foundation::IReference(*(hstring*)(&value)); } - template , int> = 0> + template + requires (!std::is_convertible_v) Windows::Foundation::IInspectable box_value(T const& value) { if constexpr (std::is_base_of_v) @@ -534,7 +537,8 @@ WINRT_EXPORT namespace winrt } } - template , int> = 0> + template + requires std::same_as hstring unbox_value_or(Windows::Foundation::IInspectable const& value, param::hstring const& default_value) { if (value) @@ -548,7 +552,8 @@ WINRT_EXPORT namespace winrt return *(hstring*)(&default_value); } - template , int> = 0> + template + requires (!std::is_same_v) T unbox_value_or(Windows::Foundation::IInspectable const& value, T const& default_value) { if (value) diff --git a/strings/base_string.h b/strings/base_string.h index 98b85590e..917a09556 100644 --- a/strings/base_string.h +++ b/strings/base_string.h @@ -701,7 +701,8 @@ WINRT_EXPORT namespace winrt return value; } - template , int> = 0> + template + requires std::same_as hstring to_hstring(T const value) { if (value) @@ -724,7 +725,8 @@ WINRT_EXPORT namespace winrt return hstring{ buffer }; } - template , int> = 0> + template + requires std::convertible_to hstring to_hstring(T const& value) { std::string_view const view(value); diff --git a/strings/base_weak_ref.h b/strings/base_weak_ref.h index efaa039b6..5f124045a 100644 --- a/strings/base_weak_ref.h +++ b/strings/base_weak_ref.h @@ -6,7 +6,8 @@ WINRT_EXPORT namespace winrt { weak_ref(std::nullptr_t = nullptr) noexcept {} - template const&, typename = std::enable_if_t const&>>> + template const&> + requires std::convertible_to const&> weak_ref(U&& object) { from_com_ref(static_cast const&>(object)); diff --git a/strings/base_windows.h b/strings/base_windows.h index 2976c91ad..d6d9071e8 100644 --- a/strings/base_windows.h +++ b/strings/base_windows.h @@ -69,13 +69,15 @@ WINRT_EXPORT namespace winrt::impl template using com_ref = std::conditional_t, T, com_ptr>; - template , int> = 0> + template + requires is_implements_v com_ref wrap_as_result(void* result) { return { &static_cast::type>*>(result)->shim(), take_ownership_from_abi }; } - template , int> = 0> + template + requires (!is_implements_v) com_ref wrap_as_result(void* result) { return { result, take_ownership_from_abi }; @@ -91,10 +93,12 @@ WINRT_EXPORT namespace winrt::impl inline constexpr bool is_com_interface_v = is_com_interface::value; // You must include to use this overload. - template , int> = 0> + template + requires (!is_com_interface_v) auto as(From* ptr); - template , int> = 0> + template + requires is_com_interface_v com_ref as(From* ptr) { #ifdef WINRT_DIAGNOSTICS @@ -112,10 +116,12 @@ WINRT_EXPORT namespace winrt::impl } // You must include to use this overload. - template , int> = 0> + template + requires (!is_com_interface_v) auto try_as(From* ptr) noexcept; - template , int> = 0> + template + requires is_com_interface_v com_ref try_as(From* ptr) noexcept { #ifdef WINRT_DIAGNOSTICS @@ -132,7 +138,8 @@ WINRT_EXPORT namespace winrt::impl return wrap_as_result(result); } - template , int> = 0> + template + requires is_com_interface_v com_ref try_as_with_reason(From* ptr, hresult& code) noexcept { #ifdef WINRT_DIAGNOSTICS @@ -341,13 +348,15 @@ WINRT_EXPORT namespace winrt::Windows::Foundation WINRT_EXPORT namespace winrt { - template , int> = 0> + template + requires (!std::is_base_of_v) auto get_abi(T const& object) noexcept { return reinterpret_cast const&>(object); } - template , int> = 0> + template + requires (!std::is_base_of_v) auto put_abi(T& object) noexcept { if constexpr (!std::is_trivially_destructible_v) @@ -358,19 +367,22 @@ WINRT_EXPORT namespace winrt return reinterpret_cast*>(&object); } - template , int> = 0> + template + requires (!std::is_base_of_v) void copy_from_abi(T& object, V&& value) { object = reinterpret_cast(value); } - template , int> = 0> + template + requires (!std::is_base_of_v) void copy_to_abi(T const& object, V& value) { reinterpret_cast(value) = object; } - template > && !std::is_convertible_v, int> = 0> + template + requires (!std::is_base_of_v> && !std::is_convertible_v) auto detach_abi(T&& object) { impl::abi_t result{};