Skip to content

Commit f06e88b

Browse files
committed
Raymond's suggestion to mark try_as_with_reason as private so composed classes dont see it
1 parent 88a826c commit f06e88b

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

cppwinrt/code_writers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ namespace cppwinrt
11371137
{%
11381138
if constexpr (!std::is_same_v<D, %>)
11391139
{
1140-
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
1140+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
11411141
check_hresult(code);
11421142
auto const abiType = *(abi_t<%>**)&castedResult;
11431143
abiType->%(%);
@@ -1156,7 +1156,7 @@ namespace cppwinrt
11561156
{%
11571157
if constexpr (!std::is_same_v<D, %>)
11581158
{
1159-
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
1159+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
11601160
check_hresult(code);
11611161
auto const abiType = *(abi_t<%>**)&castedResult;
11621162
WINRT_VERIFY_(0, abiType->%(%));
@@ -1176,7 +1176,7 @@ namespace cppwinrt
11761176
{%
11771177
if constexpr (!std::is_same_v<D, %>)
11781178
{
1179-
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
1179+
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
11801180
check_hresult(code);
11811181
auto const abiType = *(abi_t<%>**)&castedResult;
11821182
check_hresult(abiType->%(%));

strings/base_implements.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,19 +788,24 @@ namespace winrt::impl
788788
return m_inner.try_as<Qi>();
789789
}
790790

791-
template <typename Qi>
792-
auto try_as_with_reason() const noexcept
793-
{
794-
return m_inner.try_as_with_reason<Qi>();
795-
}
796-
797791
explicit operator bool() const noexcept
798792
{
799793
return m_inner.operator bool();
800794
}
795+
796+
template <typename To, typename From>
797+
friend auto winrt::impl::try_as_with_reason(From ptr) noexcept;
798+
801799
protected:
802800
static constexpr bool is_composing = true;
803801
Windows::Foundation::IInspectable m_inner;
802+
803+
private:
804+
template <typename Qi>
805+
auto try_as_with_reason() const noexcept
806+
{
807+
return m_inner.try_as_with_reason<Qi>();
808+
}
804809
};
805810

806811
template <typename D, bool>

strings/base_windows.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ namespace winrt::impl
148148
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
149149
return { wrap_as_result<To>(result), code };
150150
}
151+
152+
template <typename To, typename From>
153+
auto try_as_with_reason(From ptr) noexcept
154+
{
155+
return ptr->template try_as_with_reason<To>();
156+
}
151157
}
152158

153159
WINRT_EXPORT namespace winrt::Windows::Foundation

0 commit comments

Comments
 (0)