summaryrefslogtreecommitdiff
path: root/include/class.h
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-06-19 00:03:46 +0600
committervalmat <ufabiz@gmail.com>2014-06-19 00:03:46 +0600
commit7b64409dfb1e399c7c980fd3227d5c0432c39e6c (patch)
treebe72dc84657a189a4876e6ebebf688d01d487e81 /include/class.h
parent104cc016c84ece1d5d28aef921bb39f1f2f1e8f7 (diff)
implementation issue #97
Diffstat (limited to 'include/class.h')
-rw-r--r--include/class.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/include/class.h b/include/class.h
index e0316df..cffc7bd 100644
--- a/include/class.h
+++ b/include/class.h
@@ -202,13 +202,39 @@ public:
private:
/**
+ * Method to create the object if it is default constructable
+ * @param orig
+ * @return Base*
+ */
+ template <typename X = T>
+ typename std::enable_if<std::is_default_constructible<X>::value, Base*>::type
+ static maybeConstruct()
+ {
+ // create a new instance
+ return new X();
+ }
+
+ /**
+ * Method to create the object if it is not default constructable
+ * @param orig
+ * @return Base*
+ */
+ template <typename X = T>
+ typename std::enable_if<!std::is_default_constructible<X>::value, Base*>::type
+ static maybeConstruct()
+ {
+ // create empty instance
+ return nullptr;
+ }
+
+ /**
* Construct a new instance of the object
* @return Base
*/
virtual Base* construct() const override
{
// construct an instance
- return new T();
+ return maybeConstruct<T>();
}
/**
@@ -225,7 +251,7 @@ private:
}
/**
- * Method to clone the object if it is copy constructable
+ * Method to clone the object if it is not copy constructable
* @param orig
* @return Base*
*/