【发布时间】:2011-01-31 04:06:23
【问题描述】:
当我编写类模板并需要对这些类的成员进行完全特化时,Doxygen 无法识别特化——它只记录泛型定义,或者(如果只有特化)最后一个定义。这是一个简单的例子:
===MyClass.hpp===
#ifndef MYCLASS_HPP
#define MYCLASS_HPP
template<class T> class MyClass{
public:
static void foo();
static const int INT_CONST;
static const T TTYPE_CONST;
};
/* generic definitions */
template<class T>
void MyClass<T>::foo(){
printf("Generic foo\n");
}
template<class T>
const int MyClass<T>::INT_CONST = 5;
/* specialization declarations */
template<> void MyClass<double>::foo();
template<> const int MyClass<double>::INT_CONST;
template<> const double MyClass<double>::TTYPE_CONST;
template<> const char MyClass<char>::TTYPE_CONST;
#endif
=== MyClass.cpp ===
#include "MyClass.hpp"
/* specialization definitions */
template<>
void MyClass<double>::foo(){
printf("Specialized double foo\n");
}
template<> const int MyClass<double>::INT_CONST = 10;
template<> const double MyClass<double>::TTYPE_CONST = 3.141;
template<> const char MyClass<char>::TTYPE_CONST = 'a';
所以在这种情况下,foo() 将被记录为打印“Generic foo”,INT_CONST 将被记录为设置为 5,没有提及专业化,而 TTYPE_CONST 将被记录为设置为 'a',与没有提到 3.141,也没有表明“a”是一个特殊情况。
我需要能够记录专业化 - 无论是在 MyClass<T> 的文档中,还是在 MyClass<double>、MyClass<char> 的新页面上。我该怎么做呢? Doxygen 甚至可以处理这个问题吗?我是否可能在声明/代码结构中做错了什么,使 Doxygen 无法理解我想要什么?
我应该注意两个相关的案例:
A) 对于模板化函数,专业化工作正常,例如:
/* functions that are global/in a namespace */
template<class T> void foo(){ printf("Generic foo\n"); }
template<> void foo<double>(){ printf("Specialized double foo\n"); }
这将记录foo<T>() 和foo<double>()。
B) 如果我重新声明整个模板,即template<> class MyClass<double>{...};,那么MyClass<double> 将获得它自己的文档页面,作为一个单独的类。但这意味着实际上声明了一个全新的类 - 如果声明了 MyClass<double> 本身,则 MyClass<T> 和 MyClass<double> 之间没有关系。所以我必须重新声明这个类及其所有成员,并重复类成员的所有定义,专门针对 MyClass<double>,所有这些都让它看起来好像它们使用的是相同的模板.非常尴尬,感觉就像一个杂牌解决方案。
建议?非常感谢:)
--Ziv
【问题讨论】:
标签: doxygen template-specialization