Templates
This section describes the used conventions when using templates with classes, algorithms and iterators.
Classes and Functions
Templated classes and functions
Identifiers should be written in CamelCase.
For one template parameter use
T
or a descriptive name, e,g:.
template<typename T>
T sum( T&& a, T&& b )
{
return a+b;
}
or
template<typename Integral>
T sum( Integral&& a, Integral&& b )
{
return a+b;
}
For two template parameters, use
T
andU
, or a descriptive name.
template<typename T, typename U>
auto sum_first( T&& a, U&& b )
{
return a.first+b.first;
}
or
template<typename Pair1, typename Pair2>
auto sum_first( Pair1&& a, Pair2&& b )
{
return a.first+b.first;
}
For more than 2 template parameters, use
T1 ... Tn
or a descriptive name.
template<typename T1, typename T2, typename T3>
bool all_equal( T1&& a, T2&& b, T3&& c)
{
return (a == b) && (b == c);
}