Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document functions that are enabled with SFINAE with Doxygen?

In a library I'm developing, I often have this kind of code:

template<typename T = P, enable_if_c<has_V_field<T>> = detail::dummy>
constexpr std::size_t v(){
    return T::V;
}

template<typename T = P, disable_if_c<has_V_field<T>> = detail::dummy>
constexpr std::size_t v(){
    return 1;
}

The two functions do the same thing, but are enabled based on the type. I'd like to document only one of then and moreover, I would like if possible to show it in Doxygen without the template stuff, as constexpr std::size_t v(). For the user, the templates here have not value at all.

Is that kind of thing possible with Doxygen ?

like image 232
Baptiste Wicht Avatar asked Jul 15 '14 12:07

Baptiste Wicht


People also ask

How do I show code in doxygen?

You can put example source code in a special path defined in the doxygen config under EXAMPLE_PATH , and then insert examples with the @example tag. Doxygen will then generate an extra page containing the source of the example. It will also set a link to it from the class documentation containing the example tag.

Are doxygen commands case sensitive?

The statements in the file are case-sensitive. Comments may be placed anywhere within the file (except within quotes). Comments beginning with two hash characters ( ## ) are kept when updating the configuration file and are placed in front of the TAG they are in front of. Comments beginning with two hash characters ( ...

What is doxygen style comments?

A special comment block is a C or C++ style comment block with some additional markings, so doxygen knows it is a piece of structured text that needs to end up in the generated documentation. The next section presents the various styles supported by doxygen.


2 Answers

You can put the function you'd like to see in a conditional section like so:

#ifdef DOXYGEN_ONLY

/*! documentation for v. */
constexpr std::size_t v();

#else // actual implementation with two variants selected via SFINAE

template<typename T = P, enable_if_c<has_V_field<T>> = detail::dummy>
constexpr std::size_t v(){
    return T::V;
}

template<typename T = P, disable_if_c<has_V_field<T>> = detail::dummy>
constexpr std::size_t v(){
    return 1;
}

#endif

and then use the following configuration settings:

ENABLE_PREPROCESSING   = YES
PREDEFINED             = DOXYGEN_ONLY
like image 133
doxygen Avatar answered Oct 23 '22 08:10

doxygen


You may use \fn: http://www.doxygen.nl/manual/commands.html#cmdfn

Something like: (untested)

/*! \fn template<typename T> constexpr std::size_t v()
 *  \brief A function.
 *  \return 1 or T::V.
 */
like image 39
Jarod42 Avatar answered Oct 23 '22 07:10

Jarod42