4 #ifndef SOPHUS_COMMON_HPP
5 #define SOPHUS_COMMON_HPP
12 #include <type_traits>
24 #define SOPHUS_FUNCTION __PRETTY_FUNCTION__
25 #elif (_MSC_VER >= 1310)
26 #define SOPHUS_FUNCTION __FUNCTION__
28 #define SOPHUS_FUNCTION "unknown"
33 #ifndef EIGEN_DEVICE_FUNC
34 #define EIGEN_DEVICE_FUNC
37 #define SOPHUS_FUNC EIGEN_DEVICE_FUNC
48 -> decltype(std::declval<std::stringstream&>() << std::declval<TT>(),
52 static auto test(...) -> std::false_type;
61 static void impl(std::stringstream& stream, T&& arg) {
62 stream << std::forward<T>(arg);
66 inline void FormatStream(std::stringstream& stream,
char const* text) {
72 template <
class T,
typename... Args>
73 void FormatStream(std::stringstream& stream,
char const* text, T&& arg,
76 "One of the args has no ostream overload!");
77 for (; *text !=
'\0'; ++text) {
80 FormatStream(stream, text + 1, std::forward<Args>(args)...);
85 stream <<
"\nFormat-Warning: There are " <<
sizeof...(Args) + 1
90 template <
class... Args>
92 std::stringstream stream;
101 #if defined(SOPHUS_DISABLE_ENSURES)
103 #define SOPHUS_ENSURE(expr, ...) ((void)0)
105 #elif defined(SOPHUS_ENABLE_ENSURE_HANDLER)
108 void ensureFailed(
char const*
function,
char const* file,
int line,
109 char const* description);
112 #define SOPHUS_ENSURE(expr, ...) \
113 ((expr) ? ((void)0) \
114 : ::Sophus::ensureFailed( \
115 SOPHUS_FUNCTION, __FILE__, __LINE__, \
116 Sophus::details::FormatString(__VA_ARGS__).c_str()))
121 template <
class... Args>
123 char const* description, Args&&... args) {
124 std::printf(
"Sophus ensure failed in function '%s', file '%s', line %d.\n",
125 function, file, line);
127 std::printf(
"%s", description);
129 std::cout << details::FormatString(description, std::forward<Args>(args)...)
137 #define SOPHUS_ENSURE(expr, ...) \
138 ((expr) ? ((void)0) \
139 : Sophus::defaultEnsure(SOPHUS_FUNCTION, __FILE__, __LINE__, \
145 template <
class Scalar>
155 return Scalar(3.141592653589793238462643383279502884);
162 return static_cast<float>(1e-5);
168 return 3.141592653589793238462643383279502884f;
220 template <
bool B,
class T =
void>
225 static const bool value = std::is_unsigned<typename G::result_type>::value &&
226 std::is_unsigned<decltype(G::min())>
::value &&
227 std::is_unsigned<decltype(G::max())>
::value;
231 #endif // SOPHUS_COMMON_HPP