gpt4 book ai didi

c++ - Doxygen 提示递归 C++ 类

转载 作者:太空狗 更新时间:2023-10-29 20:23:30 25 4
gpt4 key购买 nike

我有一个简单的递归模板,它实现了 Euclid 算法(的优化版本)。 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 >!

我很惊讶为什么这是一个投诉/警告。我认为递归类型是常见且合法的。它也是许多递归模板之一,但唯一一个 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};
};

最佳答案

这个构造确实超出了 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};
};

关于c++ - Doxygen 提示递归 C++ 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33054492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com