How to document features that are enabled using SFINAE with Doxygen?

In the library that I develop, I often have code like this:

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 perform the same thing, but are activated based on the type. I would like to document only one of them and, moreover, I would like, if possible, to show it in Doxygen without template material, like constexpr std::size_t v() . For the user, the templates here do not matter at all.

Is this possible with Doxygen?

+6
source share
2 answers

You can use \fn : http://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdfn

Something like: (untested)

 /*! \fn template<typename T> constexpr std::size_t v() * \brief A function. * \return 1 or T::V. */ 
+1
source

You can put the function that you want to see in the conditional section, for example:

 #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 options:

 ENABLE_PREPROCESSING = YES PREDEFINED = DOXYGEN_ONLY 
+1
source

Source: https://habr.com/ru/post/972247/


All Articles