Drake
default_scalars.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "drake/common/autodiff.h"
4 #include "drake/common/symbolic.h"
5 
6 /// A macro that defines explicit class template instantiations for Drake's
7 /// default set of supported scalar types. This macro should only be used in
8 /// .cc files, never in .h files.
9 ///
10 /// @param SomeType the template typename to instantiate, *including* the
11 /// leading `class` or `struct` keyword.
12 ///
13 /// Currently the supported types are:
14 /// - double
15 /// - drake::AutoDiffXd
16 /// - drake::symbolic::Expression
17 ///
18 /// Example `my_system.h`:
19 /// @code
20 /// namespace sample {
21 /// template <typename T>
22 /// class MySystem final : public LeafSystem<T> {
23 /// ...
24 /// @endcode
25 ///
26 /// Example `my_system.cc`:
27 /// @code
28 /// #include "my_system.h"
29 ///
30 /// #include "drake/common/default_scalars.h"
31 ///
32 /// DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(
33 /// class ::sample::MySystem)
34 /// @endcode
35 ///
36 /// See also @ref system_scalar_conversion.
37 #define DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS( \
38  SomeType) \
39 DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( \
40  SomeType) \
41 template SomeType<::drake::symbolic::Expression>;
42 
43 /// A macro to that defines explicit class template instantiations for Drake's
44 /// default set of supported scalar types, excluding all symbolic types. This
45 /// macro should only be used in .cc files, never in .h files. This is
46 /// identical to DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS
47 /// except that it does not define support for any drake::symbolic types.
48 #define \
49  DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( \
50  SomeType) \
51 template SomeType<double>; \
52 template SomeType<::drake::AutoDiffXd>;