Menu

C++: doc for template specialization?

Ziv Wities
2010-03-15
2013-06-11
  • Ziv Wities

    Ziv Wities - 2010-03-15

    When documenting a member of a templated class, Doxygen documents the default implementation but not any specializations (or even more confusingly - the first specialization, but not any others, when there's no default).

    For example:

    FooClass.h
    #ifndef FOO_CLASS_H
    #define FOO_CLASS_H

    enum FooClassType {Type_A, Type_B};

    template<FooClassType T>
    class FooClass {
       public:
       /**
        * A value depending on the templated type.
        */
       static const int nFooValue;
    };
    #endif

    FooClass.cpp
    #include "FooClass.h"

    template<>
    const int FooClass<FooClassType::Type_A>::nFooValue = 1;

    template<>
    const int FooClass<FooClassType::Type_B>::nFooValue = 2;

    In this case, I'd simply get a docpage for FooClass<FooClassType T>, documenting FooClass<FooClassType T>::nFooValue as being 1. Not what I want…

    Is there any way to produce documentation which lists all specializations in the documentation of FooClass<T>::nFooValue? Or perhaps to produce seperate pages for FooClass<Type_A>, FooClass<Type_B>?

    Thanks much,

    Ziv

     
  • Ziv Wities

    Ziv Wities - 2010-03-21

    OK, I've understood the problem. My bad, clearly - this isn't a problem with doxygen, it's my code that's wrong. Compiles and runs fine in my local environment, but still wrong!

    My header file should have read as follows:

    FooClass.h
    #ifndef FOO_CLASS_H
    #define FOO_CLASS_H

    enum FooClassType {Type_A, Type_B};

    template<FooClassType T>
    class FooClass {
    public:
    /**
    * A value depending on the templated type.
    */
    static const int nFooValue;
    };

    template<>
    class FooClass<Type_A>
    {
    public:
    static const int nFooValue;
    };

    template<>
    class FooClass<Type_B>
    {
    public:
    static const int nFooValue;
    };

    #endif

    Without explicitly declaring the template specialization, the code is not well-defined (and cpp  files calling FooClass<Type_A> don't know to look for a specialization).

     
  • Ziv Wities

    Ziv Wities - 2010-03-28

    Seems my original code was correct after all, except I should have declared the specialization in the headers. So doxygen is fialing to document members it should, and I find that this bug has been previously noted, and apparantly not been fixed yet.

    Thanks much!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.