From 8feef376280dadcbf6de9cb5f2f43693112d46f4 Mon Sep 17 00:00:00 2001 From: Raymond Chen Date: Thu, 24 Jun 2021 11:41:33 -0700 Subject: [PATCH] IReference operators in level-1 header should be forward declarations Implementation relies on methods in the top-level header, so defer implementation to there. This reverts the change to base_reference_produce.h from #906 and reduces base_reference_produce_1.h to merely forward references. This is enough to get structures to compile, although you cannot meaningfully use any IReferences in them until you include Windows.Foundation.h (which is consistent with existing rules for namespace headers). --- strings/base_reference_produce.h | 28 +++++++++++++++++++ strings/base_reference_produce_1.h | 20 ++----------- .../test_component_no_pch.idl | 7 +++++ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 1965efc7a..8228cbc4c 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -397,7 +397,35 @@ 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 index 7c5143821..0eb9b4b70 100644 --- a/strings/base_reference_produce_1.h +++ b/strings/base_reference_produce_1.h @@ -2,24 +2,8 @@ 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(); - } + bool operator==(IReference const& left, IReference const& right); template - bool operator!=(IReference const& left, IReference const& right) - { - return !(left == right); - } + bool operator!=(IReference const& left, IReference const& right); } diff --git a/test/test_component_no_pch/test_component_no_pch.idl b/test/test_component_no_pch/test_component_no_pch.idl index 11e5cbebc..b576313c8 100644 --- a/test/test_component_no_pch/test_component_no_pch.idl +++ b/test/test_component_no_pch/test_component_no_pch.idl @@ -33,4 +33,11 @@ namespace test_component_no_pch Int32 Second; }; } + + // This structure verifies that the structure can at least be declared + // (but perhaps not meaningfully consumed) without having first included Windows.Foundation.h. + struct StructWithReference + { + Windows.Foundation.IReference OptionalValue; + }; }