Is it possible to include a parametrized method in an IDL file like this:
runtimeclass A
{
A();
T f<T>();
};
What are the alternatives?
The Windows Runtime type system only supports a fixed set of generic types, namely the types in the Windows.Foundation
namespace (such as IAsyncOperation<T>
and EventHandler<T>
) and those in the Windows.Foundation.Collections
namespace (such as IVector<T>
). Even these generic types must be specialized with a concrete type (such as IVector<HSTRING>
) when defining your own type.
The closest thing to what you specified is to use IInspectable
as your parameter type / return type. This can hold any object type or any scalar value (via IReference<T>
), but there is no type-safety enforced by the compiler and no way to infer the return type from the parameter etc.
If you know ahead of time which concrete types your clients will use (e.g. HSTRING
and Int32
) then you can encode them directly at the ABI level as HSTRING FooString(HSTRING arg)
and Int32 FooInt32(Int32 arg)
and then your implementation can use a standard templated C++ function.