Doxygen 抱怨递归 C++ 类

kam*_*aze 4 c++ templates doxygen

我有一个简单的递归模板,它实现了欧几里得算法(的优化版本)。Doxygen 对此抱怨道:

/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class units::euclid< Rhs, Lhs%Rhs >!

/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class euclid< Rhs, Lhs%Rhs >!

/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class units::euclid< Rhs, Lhs%Rhs >!

/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class euclid< Rhs, Lhs%Rhs >!
Run Code Online (Sandbox Code Playgroud)

我很惊讶为什么这是一个投诉/警告。我认为递归类型是常见且合法的。它也是众多递归模板之一,但也是 doxygen 唯一抱怨的一个。令我惊讶的是,我只发现 doxygen 错误检测递归的类似问题。

如果您有兴趣,这里是代码:

/**
 * Implements Euclid's algorithm to find the GCD between two integers.
 *
 * @tparam Lhs,Rhs
 *  The values to get the GCD for
 */
template <int Lhs, int Rhs>
struct euclid : euclid<Rhs, Lhs % Rhs> {
};

/**
 * Terminates Euclid's algorithm.
 *
 * @tparam Gcd
 *  The GCD to return
 * @see euclid
 */
template <int Gcd>
struct euclid<Gcd, 0> {
    /**
     * The GCD of the two original values.
     */
    static constexpr int const value{Gcd};
};
Run Code Online (Sandbox Code Playgroud)

dox*_*gen 7

这种构造确实超出了 doxygen 的解析能力。

由于此类的用户不知道它是否以递归方式实现,因此您可以使用以下解决方法:

/**
 * Implements Euclid's algorithm to find the GCD between two integers.
 *
 * @tparam Lhs,Rhs
 *  The values to get the GCD for
 */
template <int Lhs, int Rhs>
struct euclid /** @cond */ : euclid<Rhs, Lhs % Rhs> /** @endcond */ {
  /** @cond */
};

template <int Gcd>
struct euclid<Gcd, 0> {
  /** @endcond
   * The GCD of the two original values.
   */
  static constexpr int const value {Gcd};
};
Run Code Online (Sandbox Code Playgroud)