From 792bdb89caa0618535eb6b755e36f103e1445168 Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Sun, 28 Mar 2021 07:35:35 -0700 Subject: [PATCH 1/2] IReference operators need to go into the level-1 header That way they are defined whenever the interface is defined. --- cppwinrt/code_writers.h | 8 ++++++++ cppwinrt/cppwinrt.vcxproj | 1 + cppwinrt/cppwinrt.vcxproj.filters | 3 +++ cppwinrt/file_writers.h | 1 + strings/base_reference_produce.h | 28 ---------------------------- strings/base_reference_produce_1.h | 25 +++++++++++++++++++++++++ 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 strings/base_reference_produce_1.h diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 37f5f4327..2f3f2e103 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -3256,4 +3256,12 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable w.write(strings::base_xaml_typename); } } + + static void write_namespace_special_1(writer& w, std::string_view const& namespace_name) + { + if (namespace_name == "Windows.Foundation") + { + w.write(strings::base_reference_produce_1); + } + } } diff --git a/cppwinrt/cppwinrt.vcxproj b/cppwinrt/cppwinrt.vcxproj index ee4fd3f3a..ac287d6bd 100644 --- a/cppwinrt/cppwinrt.vcxproj +++ b/cppwinrt/cppwinrt.vcxproj @@ -74,6 +74,7 @@ + diff --git a/cppwinrt/cppwinrt.vcxproj.filters b/cppwinrt/cppwinrt.vcxproj.filters index 7720e5dfc..ae46f25b3 100644 --- a/cppwinrt/cppwinrt.vcxproj.filters +++ b/cppwinrt/cppwinrt.vcxproj.filters @@ -115,6 +115,9 @@ strings + + strings + strings diff --git a/cppwinrt/file_writers.h b/cppwinrt/file_writers.h index c210b6f47..f56267f93 100644 --- a/cppwinrt/file_writers.h +++ b/cppwinrt/file_writers.h @@ -126,6 +126,7 @@ namespace cppwinrt auto wrap_type = wrap_type_namespace(w, ns); w.write_each(members.interfaces); } + write_namespace_special_1(w, ns); write_close_file_guard(w); w.swap(); diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 8228cbc4c..1965efc7a 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -397,35 +397,7 @@ namespace winrt::impl static auto make(array_view const& value) { return Windows::Foundation::PropertyValue::CreateRectArray(value); } using itf = Windows::Foundation::IReferenceArray; }; -} - -WINRT_EXPORT namespace winrt::Windows::Foundation -{ - template - bool operator==(IReference const& left, IReference const& right) - { - if (get_abi(left) == get_abi(right)) - { - return true; - } - - if (!left || !right) - { - return false; - } - return left.Value() == right.Value(); - } - - template - bool operator!=(IReference const& left, IReference const& right) - { - return !(left == right); - } -} - -namespace winrt::impl -{ template T unbox_value_type(From&& value) { diff --git a/strings/base_reference_produce_1.h b/strings/base_reference_produce_1.h new file mode 100644 index 000000000..7c5143821 --- /dev/null +++ b/strings/base_reference_produce_1.h @@ -0,0 +1,25 @@ + +WINRT_EXPORT namespace winrt::Windows::Foundation +{ + template + bool operator==(IReference const& left, IReference const& right) + { + if (get_abi(left) == get_abi(right)) + { + return true; + } + + if (!left || !right) + { + return false; + } + + return left.Value() == right.Value(); + } + + template + bool operator!=(IReference const& left, IReference const& right) + { + return !(left == right); + } +} From 2f1801f7c87a6c31e3aeb6f9a48fd9b86572a7c9 Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Mon, 29 Mar 2021 11:37:29 -0700 Subject: [PATCH 2/2] Clean up obsolete checks left over from early xlang --- cppwinrt/code_writers.h | 13 +++---------- cppwinrt/file_writers.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 10f80ca95..9bed6b968 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -3248,19 +3248,12 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable type); } - static void write_namespace_special(writer& w, std::string_view const& namespace_name, cache const& c) + static void write_namespace_special(writer& w, std::string_view const& namespace_name) { if (namespace_name == "Windows.Foundation") { - if (c.find("Windows.Foundation.PropertyValue")) - { - w.write(strings::base_reference_produce); - } - if (c.find("Windows.Foundation.Deferral")) - { - w.write(strings::base_deferral); - } - + w.write(strings::base_reference_produce); + w.write(strings::base_deferral); w.write(strings::base_coroutine_foundation); } else if (namespace_name == "Windows.Foundation.Collections") diff --git a/cppwinrt/file_writers.h b/cppwinrt/file_writers.h index fa8a10418..8dfd6f09d 100644 --- a/cppwinrt/file_writers.h +++ b/cppwinrt/file_writers.h @@ -202,7 +202,7 @@ namespace cppwinrt w.write_each(members.classes); } - write_namespace_special(w, ns, c); + write_namespace_special(w, ns); write_close_file_guard(w); w.swap();