Drake
dummy_value.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <limits>
4 
5 namespace drake {
6 
7 /// Provides a "dummy" value for a ScalarType -- a value that is unlikely to be
8 /// mistaken for a purposefully-computed value, useful for initializing a value
9 /// before the true result is available.
10 ///
11 /// Defaults to using std::numeric_limits::quiet_NaN when available; it is a
12 /// compile-time error to call the unspecialized dummy_value::get() when
13 /// quiet_NaN is unavailable.
14 ///
15 /// See autodiff_overloads.h to use this with Eigen's AutoDiffScalar.
16 template <typename T>
17 struct dummy_value {
18  static constexpr T get() {
19  static_assert(std::numeric_limits<T>::has_quiet_NaN,
20  "Custom scalar types should specialize this struct");
21  return std::numeric_limits<T>::quiet_NaN();
22  }
23 };
24 
25 template <>
26 struct dummy_value<int> {
27  static constexpr int get() {
28  // D is for "Dummy". We assume as least 32 bits (per cppguide) -- if `int`
29  // is larger than 32 bits, this will leave some fraction of the bytes zero
30  // instead of 0xDD, but that's okay.
31  return 0xDDDDDDDD;
32  }
33 };
34 
35 } // namespace drake
Definition: automotive_demo.cc:88
Provides a "dummy" value for a ScalarType – a value that is unlikely to be mistaken for a purposeful...
Definition: dummy_value.h:17