Template

Breathe has support for class and function templates. They are output as follows. For a class with a single template parameter:

.. doxygenclass:: templateclass
   :project: template_class
   :members:

It renders as:


template<typename T>
class templateclass

a class with a template parameter

模板参数

T – this is the template parameter

Public Functions

inline templateclass()

default constructor

inline templateclass(T const &m)

constructor with template argument

参数

m – the argument

T method(T const &t)

member accepting template argument and returning template argument

参数

t – argument of type T

返回

returns value of type T


With multiple template parameters it renders as:


template<typename T, typename U, int N>
class anothertemplateclass

a class with three template parameters

模板参数
  • T – this is the first template parameter

  • U – this is the second template parameter

  • N – this is the third template parameter, it is a non-type parameter

Public Functions

inline anothertemplateclass()

default constructor

inline anothertemplateclass(T const &m1, U const &m2)

constructor with two template argument

参数
  • m1 – first argument

  • m2 – second argument

U method(T const &t)

member accepting template argument and returning template argument

参数

t – argument

返回

returns value of type U


A function with single template parameter renders as:


template<typename T>
T function1(T arg1)

a function with one template arguments

模板参数

T – this is the template parameter

参数

arg1 – argument of type T

返回

return value of type T


If specialized for a given type it renders as:


template<>
std::string function1<std::string>(std::string arg1)

a function with one template argument specialized for std::string

参数

arg1 – argument of type std::string

返回

return value of type std::string


With multiple template parameters it renders as:


template<typename T, typename U, int N>
T function2(T arg1, U arg2)

a function with three template arguments

模板参数
  • T – this is the first template parameter

  • U – this is the second template parameter

  • N – this is the third template parameter, it is a non-type parameter

参数
  • arg1 – first argument of type T

  • arg2 – second argument of type U

返回

return value of type T