Skip to content

Commit

Permalink
Change if_then_else to be inline
Browse files Browse the repository at this point in the history
Users will expect it to be comparable in performance to the ternary
conditional operator, so we should do it that way.
  • Loading branch information
jwnimmer-tri committed Feb 23, 2017
1 parent 96a6e87 commit 664e849
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 2 additions & 6 deletions drake/common/double_overloads.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#include "drake/common/double_overloads.h"

namespace drake {
double if_then_else(const bool f_cond, const double v_then,
const double v_else) {
return f_cond ? v_then : v_else;
}
} // namespace drake
// For now, this is an empty .cc file that only serves to confirm that
// double_overloads.h is a stand-alone header.
5 changes: 4 additions & 1 deletion drake/common/double_overloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ namespace drake {
/// v_else are evaluated regardless of the evaluation of @p f_cond. In contrast,
/// only one of @p v_then or @p v_else is evaluated in C++'s conditional
/// expression <tt>f_cond ? v_then : v_else</tt>.
double if_then_else(bool f_cond, double v_then, double v_else);
inline double if_then_else(bool f_cond, double v_then, double v_else) {
return f_cond ? v_then : v_else;
}

} // namespace drake

0 comments on commit 664e849

Please sign in to comment.