Skip to content

Commit 96f637e

Browse files
committed
Remove try_as_with_reason and just call as
1 parent d4d5733 commit 96f637e

3 files changed

Lines changed: 8 additions & 34 deletions

File tree

cppwinrt/code_writers.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,15 +1130,14 @@ namespace cppwinrt
11301130
{
11311131
// we intentionally ignore errors when unregistering event handlers to be consistent with event_revoker
11321132
//
1133-
// The `noexcept` versions will crash if check_hresult throws but that is no different than previous
1133+
// The `noexcept` versions will crash if .as<>() throws but that is no different than previous
11341134
// behavior where it would not check the cast result and nullptr crash. At least the exception will terminate
11351135
// immediately while preserving the error code and local variables.
11361136
format = R"( template <typename D%> auto consume_%<D%>::%(%) const noexcept
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<%>();
1141-
check_hresult(code);
1140+
auto const& castedResult = static_cast<D const*>(this)->template as<%>();
11421141
auto const abiType = *(abi_t<%>**)&castedResult;
11431142
abiType->%(%);
11441143
}
@@ -1156,8 +1155,7 @@ namespace cppwinrt
11561155
{%
11571156
if constexpr (!std::is_same_v<D, %>)
11581157
{
1159-
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
1160-
check_hresult(code);
1158+
auto const& castedResult = static_cast<D const*>(this)->template as<%>();
11611159
auto const abiType = *(abi_t<%>**)&castedResult;
11621160
WINRT_VERIFY_(0, abiType->%(%));
11631161
}
@@ -1176,8 +1174,7 @@ namespace cppwinrt
11761174
{%
11771175
if constexpr (!std::is_same_v<D, %>)
11781176
{
1179-
auto const& [castedResult, code] = static_cast<D const*>(this)->template try_as_with_reason<%>();
1180-
check_hresult(code);
1177+
auto const& castedResult = static_cast<D const*>(this)->template as<%>();
11811178
auto const abiType = *(abi_t<%>**)&castedResult;
11821179
check_hresult(abiType->%(%));
11831180
}

strings/base_implements.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,15 +783,15 @@ namespace winrt::impl
783783
struct WINRT_IMPL_EMPTY_BASES root_implements_composing_outer<true>
784784
{
785785
template <typename Qi>
786-
auto try_as() const noexcept
786+
auto as() const noexcept
787787
{
788-
return m_inner.try_as<Qi>();
788+
return m_inner.as<Qi>();
789789
}
790790

791791
template <typename Qi>
792-
auto try_as_with_reason() const noexcept
792+
auto try_as() const noexcept
793793
{
794-
return m_inner.try_as_with_reason<Qi>();
794+
return m_inner.try_as<Qi>();
795795
}
796796

797797
explicit operator bool() const noexcept

strings/base_windows.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,6 @@ namespace winrt::impl
131131
ptr->QueryInterface(guid_of<To>(), &result);
132132
return wrap_as_result<To>(result);
133133
}
134-
135-
template <typename To, typename From, std::enable_if_t<is_com_interface_v<To>, int> = 0>
136-
std::pair<com_ref<To>, hresult> try_as_with_reason(From* ptr) noexcept
137-
{
138-
#ifdef WINRT_DIAGNOSTICS
139-
get_diagnostics_info().add_query<To>();
140-
#endif
141-
142-
if (!ptr)
143-
{
144-
return { nullptr, 0 };
145-
}
146-
147-
void* result{};
148-
hresult code = ptr->QueryInterface(guid_of<To>(), &result);
149-
return { wrap_as_result<To>(result), code };
150-
}
151134
}
152135

153136
WINRT_EXPORT namespace winrt::Windows::Foundation
@@ -222,12 +205,6 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
222205
return impl::try_as<To>(m_ptr);
223206
}
224207

225-
template <typename To>
226-
auto try_as_with_reason() const noexcept
227-
{
228-
return impl::try_as_with_reason<To>(m_ptr);
229-
}
230-
231208
template <typename To>
232209
void as(To& to) const
233210
{

0 commit comments

Comments
 (0)