From 365857fef04235a5c91d220b52306984e922513b Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Fri, 26 Nov 2010 18:31:37 +0100
Subject: [PATCH] Move DefaultFunction to constant.h so it can be used
 elsewhere. For example, it can now be used in Conditional, which is done as
 well.

---
 libwccl/ops/functions/conditional.h |  7 +------
 libwccl/ops/functions/constant.h    | 13 +++++++++++++
 libwccl/ops/operator.h              | 10 ----------
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/libwccl/ops/functions/conditional.h b/libwccl/ops/functions/conditional.h
index 73e7d0a..763339c 100644
--- a/libwccl/ops/functions/conditional.h
+++ b/libwccl/ops/functions/conditional.h
@@ -23,7 +23,7 @@ public:
 	Conditional(
 		const BoolFunctionPtr& cond_expr,
 		const ArgFunctionPtr& iftrue_expr,
-		const ArgFunctionPtr& iffalse_expr = Default())
+		const ArgFunctionPtr& iffalse_expr = detail::DefaultFunction<T>())
 		: cond_expr_(cond_expr), iftrue_expr_(iftrue_expr), iffalse_expr_(iffalse_expr)
 	{
 		BOOST_ASSERT(cond_expr_);
@@ -57,11 +57,6 @@ protected:
 	const ArgFunctionPtr iftrue_expr_;
 	const ArgFunctionPtr iffalse_expr_;
 
-	static const ArgFunctionPtr& Default() {
-		static ArgFunctionPtr x(new Constant<T>(T()));
-		return x;
-	}
-
 	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
 	/**
 	 * Evaluate the predicate. If it is true, evaluate and return value of
diff --git a/libwccl/ops/functions/constant.h b/libwccl/ops/functions/constant.h
index 006419f..6ab8398 100644
--- a/libwccl/ops/functions/constant.h
+++ b/libwccl/ops/functions/constant.h
@@ -61,6 +61,19 @@ private:
 	const boost::shared_ptr<const T> value_;
 };
 
+namespace detail {
+
+/**
+ * Helper function creating a default Function<T> object - a Constant<T>
+ * that is returning default Value of given type T.
+ */
+template<class T>
+static boost::shared_ptr<Function<T> > DefaultFunction() {
+	static boost::shared_ptr<Function<T> > default_fun(new Constant<T>((T())));
+	return default_fun;
+}
+
+}
 
 } /* end ns Wccl */
 
diff --git a/libwccl/ops/operator.h b/libwccl/ops/operator.h
index 9bbb53f..767f958 100644
--- a/libwccl/ops/operator.h
+++ b/libwccl/ops/operator.h
@@ -299,16 +299,6 @@ Operator<T>& Operator<T>::operator=(const Operator& other) {
 	return *this;
 }
 
-namespace detail {
-
-template<class T>
-static boost::shared_ptr<Function<T> > DefaultFunction() {
-	static boost::shared_ptr<Function<T> > default_fun(new Constant<T>((T())));
-	return default_fun;
-}
-
-}
-
 template <class T> inline
 Operator<T>::Operator()
 	: FunctionalOperator((Variables())),
-- 
GitLab