winrt::unbox_value_or function template (C++/WinRT)

A function template that unwraps (or unboxes) a scalar value from inside a reference class object, with a fallback value, so that it can be processed in a function that expects IInspectable. An overload of the function also exists for winrt::hstring. For more details, and code examples, see Boxing and unboxing scalar values to IInspectable with C++/WinRT.

Syntax

template <typename T>
hstring unbox_value_or(winrt::Windows::Foundation::IInspectable const& value, winrt::hstring const& default_value);

template <typename T, typename = std::enable_if_t<!std::is_same_v<T, winrt::hstring>>>
T unbox_value_or(winrt::Windows::Foundation::IInspectable const& value, T const& default_value);

Template parameters

typename T A scalar type.

Parameters

default_value A fallback value to use should coercing the reference class object to the specified value type not be possible.

value A reference class object containing a boxed value.

Return value

The scalar value contained inside the reference class object, or default_value if unboxing to the specified value type is not possible.

Requirements

Minimum supported SDK: Windows SDK version 10.0.17134.0 (Windows 10, version 1803)

Namespace: winrt

Header %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\Windows.Foundation.h

See also