From 21f33d337cc26cd004a6c7625701f3f5a19193e4 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Fri, 4 Feb 2011 00:51:31 +0000 Subject: [PATCH] Added casting to value type in ValueWithDefault, allows use in 'if' statements, etc. This was needed for the previous check-in of the global debug flags. Also added code comments. --- gtsam/base/types.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gtsam/base/types.h b/gtsam/base/types.h index 6370d95db..575d53806 100644 --- a/gtsam/base/types.h +++ b/gtsam/base/types.h @@ -54,15 +54,18 @@ namespace gtsam { template struct ValueWithDefault { T value; - ValueWithDefault() : - value(defaultValue) { - } - ValueWithDefault(const T& _value) : - value(_value) { - } - T& operator*() { - return value; - } + + /** Default constructor, initialize to default value supplied in template argument */ + ValueWithDefault() : value(defaultValue) {} + + /** Initialize to the given value */ + ValueWithDefault(const T& _value) : value(_value) {} + + /** Operator to access the value */ + T& operator*() { return value; } + + /** Implicit conversion allows use in if statements for bool type, etc. */ + operator T() const { return value; } }; }