Skip to content

Commit

Permalink
Raymond's suggestion to mark try_as_with_reason as private so compose…
Browse files Browse the repository at this point in the history
…d classes dont see it
  • Loading branch information
dmachaj committed Nov 15, 2024
1 parent 88a826c commit f06e88b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ namespace cppwinrt
{%
if constexpr (!std::is_same_v<D, %>)
{
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
check_hresult(code);
auto const abiType = *(abi_t<%>**)&castedResult;
abiType->%(%);
Expand All @@ -1156,7 +1156,7 @@ namespace cppwinrt
{%
if constexpr (!std::is_same_v<D, %>)
{
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
check_hresult(code);
auto const abiType = *(abi_t<%>**)&castedResult;
WINRT_VERIFY_(0, abiType->%(%));
Expand All @@ -1176,7 +1176,7 @@ namespace cppwinrt
{%
if constexpr (!std::is_same_v<D, %>)
{
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
auto const [castedResult, code] = impl::try_as_with_reason<%, D const*>(static_cast<D const*>(this));
check_hresult(code);
auto const abiType = *(abi_t<%>**)&castedResult;
check_hresult(abiType->%(%));
Expand Down
17 changes: 11 additions & 6 deletions strings/base_implements.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,19 +788,24 @@ namespace winrt::impl
return m_inner.try_as<Qi>();
}

template <typename Qi>
auto try_as_with_reason() const noexcept
{
return m_inner.try_as_with_reason<Qi>();
}

explicit operator bool() const noexcept
{
return m_inner.operator bool();
}

template <typename To, typename From>
friend auto winrt::impl::try_as_with_reason(From ptr) noexcept;

protected:
static constexpr bool is_composing = true;
Windows::Foundation::IInspectable m_inner;

private:
template <typename Qi>
auto try_as_with_reason() const noexcept
{
return m_inner.try_as_with_reason<Qi>();
}
};

template <typename D, bool>
Expand Down
6 changes: 6 additions & 0 deletions strings/base_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ namespace winrt::impl
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
return { wrap_as_result<To>(result), code };
}

template <typename To, typename From>
auto try_as_with_reason(From ptr) noexcept
{
return ptr->template try_as_with_reason<To>();
}
}

WINRT_EXPORT namespace winrt::Windows::Foundation
Expand Down

0 comments on commit f06e88b

Please sign in to comment.