Similar to the Eigen library, many classes in Drake use a template argument to specify the numeric scalar type to use for computation.
We typically name that template argument <T>. For an example, see the class drake::math::RigidTransform.
Most scalar-templated classes in Drake only support a small, fixed set of scalar types:
When Drake documentation refers to "default scalars", it means all three of the types above.
Alternatively, reference to "default nonsymbolic scalars" means all except drake::symbolic::Expression.
For code within Drake, we offer Doxygen custom commands to document the <T> template parameter in the conventional cases:
@tparam_default_scalar for the default scalars.@tparam_nonsymbolic_scalar for the default nonsymbolic scalars.@tparam_double_only for only the double scalar and nothing else.All three commands assume that the template parameter is named T. When possible, prefer to use these commands instead of writing out a @tparam line manually.
Namespaces | |
| namespace | drake |
Variables | |
| template<typename T> | |
| constexpr bool | is_default_scalar |
Class template instantiation macros | |||
These macros either declare or define class template instantiations for Drake's supported scalar types (see Default Scalars), either "default scalars" or "default nonsymbolic scalars". Use the DECLARE macros only in .h files; use the DEFINE macros only in .cc files.
Example my_system.h: #include "drake/common/default_scalars.h"
namespace sample {
template <typename T>
...
};
} // namespace sample
class ::sample::MySystem);
A superclass template that extends System with some convenience utilities that are not applicable to ... Definition leaf_system.h:42 #define DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( SomeType) Declares that template instantiations exist for Drake's default scalars. Definition default_scalars.h:150 Example my_system.cc: #include "my_system.h"
class ::sample::MySystem);
#define DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(SomeType) Defines template instantiations for Drake's default scalars. Definition default_scalars.h:115 See also System Scalar Conversion. | |||
| #define | DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(SomeType) | ||
| Defines template instantiations for Drake's default scalars. | |||
| #define | DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS(SomeType) | ||
| Defines template instantiations for Drake's default nonsymbolic scalars. | |||
| #define | DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( SomeType) | ||
| Declares that template instantiations exist for Drake's default scalars. | |||
| #define | DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS(SomeType) | ||
| Declares that template instantiations exist for Drake's default nonsymbolic scalars. | |||
Function template instantiation macros | |||
These macros define template function instantiations for Drake's supported scalar types (see Default Scalars), either "default scalars" or "default nonsymbolic scalars". Use the DEFINE macros only in .cc files.
Example example.h: #include "drake/common/default_scalars.h"
namespace sample {
template <typename T>
double Func1(const T&);
template <typename T, typename U>
double Func2(const T&, const U&);
template <typename T>
class SomeClass {
...
template <typename U>
SomeClass cast() const;
...
};
} // namespace sample
Example example.cc: #include "example.h"
namespace sample {
template <typename T>
double Func1(const T&) {
...
}
template <typename T, typename U>
double Func2(const T&, const U&) {
...
}
template <typename T>
template <typename U>
SomeClass<T>::SomeClass::cast() const {
...
};
// N.B. Place the macro invocation inside the functions' namespace.
&Func1<T>,
&Func2<T, U>,
&SomeClass<T>::template cast<U>
));
} // namespace sample
#define DRAKE_DEFINE_FUNCTION_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(FunctionPointersTuple) Defines template instantiations for Drake's default scalars. Definition default_scalars.h:250
| |||
| #define | DRAKE_DEFINE_FUNCTION_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(FunctionPointersTuple) | ||
| Defines template instantiations for Drake's default scalars. | |||
| #define | DRAKE_DEFINE_FUNCTION_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS(FunctionPointersTuple) | ||
| Defines template instantiations for Drake's default nonsymbolic scalars. | |||
| #define DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS | ( | SomeType | ) |
Declares that template instantiations exist for Drake's default nonsymbolic scalars.
This should only be used in .h files, never in .cc files.
| #define DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS | ( | SomeType | ) |
Declares that template instantiations exist for Drake's default scalars.
This should only be used in .h files, never in .cc files.
| #define DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS | ( | SomeType | ) |
Defines template instantiations for Drake's default nonsymbolic scalars.
This should only be used in .cc files, never in .h files.
| #define DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS | ( | SomeType | ) |
Defines template instantiations for Drake's default scalars.
This should only be used in .cc files, never in .h files.
| #define DRAKE_DEFINE_FUNCTION_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS | ( | FunctionPointersTuple | ) |
Defines template instantiations for Drake's default nonsymbolic scalars.
This should only be used in .cc files, never in .h files.
| #define DRAKE_DEFINE_FUNCTION_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS | ( | FunctionPointersTuple | ) |
Defines template instantiations for Drake's default scalars.
This should only be used in .cc files, never in .h files.
|
constexpr |