Skip to content

Support binding std::optional<T> implementation to IReference<T> parameters #1006

@jonwis

Description

@jonwis

Assume I have this IDL:

runtimeclass MyThing {
    Windows.Foundation.IReference<UInt32> GetSize();
}

And my implementation says:

struct MyThing : MyThingT<MyThing> {
    std::optional<uint32_t> m_sizeComputed;
    winrt::Windows::Foundation::IReference<uint32_t> GetSize() {
        if (!m_sizeComputed) {
            return nullptr;
        } else {
            return winrt::box_value(m_sizeComputed.value()).as<winrt::Windows::Foundation<IReference<uint32_t>>>();
    }
}

I'd like this to be easier on the implementation, where instead I can just say:

struct MyThing : MyThingT<MyThing> {
    std::optional<uint32_t> m_sizeComputed;
    const std::optional<uint32_t> GetSize() { return m_sizeComputed; }
}

Is there a way for C++/WinRT's shims to match up IReference<T>-things (properties, returned types, parameters) and auto-convert them to/from std::optional<T>?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions