Microsoft Dev Blogs

How well does C++/WinRT com_ptr support class template argument deduction (CTAD)?

thumbnail

C++/WinRT CTAD Support Summary

Overview

C++/WinRT does not support class template argument deduction (CTAD) directly. There is no constructor provided by C++/WinRT that takes a template parameter for CTAD.

Constructor Options

  • C++/WinRT does not have a constructor that copies an existing pointer due to ambiguity in ownership.
  • A deduction guide could potentially be created for the "take ownership" constructor, but it is not recommended for consumers to make their own guides.

Workaround

  • Instead of relying on CTAD, a maker function can be used to create a new instance of the class.
  • Additional precautions may need to be taken to ensure the proper type is being created, such as checking for derivation from a specific base class.

Bonus Information

  • C++/CX does not support classic COM interfaces, only Windows Runtime interfaces, therefore CTAD support is not applicable.

In conclusion, C++/WinRT does not offer direct support for CTAD, but alternative methods such as maker functions can be utilized to achieve similar functionality.