如何记录接受回调的函数?

How to document a function that takes a callback?

我正在编写一个异步库,我的一些方法将回调作为参数:

/// \brief Opens a connection to the remote server defined by the parameters passed in the constructor.
/// \param[in] callback Callback passed when the connection is estabelished or fails.
/// \return Any errors encountered by the library or the OS.
virtual connect(std::function<void(std::error_code ec)> callback) noexcept = 0;

如何在 Doxygen 中记录回调的参数?

您想要一种以嵌套方式(函数参数内的函数)记录仿函数本身的方法,但 Doxygen 不支持该 AFAIK。您可以使用 \parblock and some Doxygen Markdown. Another manual way would be to move the callback definition to a typedef and document it there with \typedef 手动执行此操作,因为 Doxygen 不以这种方式支持仿函数,这将再次需要手动操作。