From b67ecdd0715bc8c21a817d389b568d4c136fb1d1 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(win7-laptop)>
Date: Sun, 28 Nov 2010 04:09:36 +0100
Subject: [PATCH] Reworking DefaultFunction a bit, putting const.

---
 libwccl/ops/functions/conditional.h | 12 ++++++++----
 libwccl/ops/functions/constant.h    |  2 +-
 libwccl/ops/operator.h              |  4 ++--
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libwccl/ops/functions/conditional.h b/libwccl/ops/functions/conditional.h
index 763339c..af07a74 100644
--- a/libwccl/ops/functions/conditional.h
+++ b/libwccl/ops/functions/conditional.h
@@ -17,13 +17,13 @@ namespace Wccl {
 template<class T>
 class Conditional : public Function<T> {
 public:
-	typedef boost::shared_ptr<Function<T> > ArgFunctionPtr;
-	typedef boost::shared_ptr<Function<Bool> > BoolFunctionPtr;
+	typedef boost::shared_ptr<const Function<T> > ArgFunctionPtr;
+	typedef boost::shared_ptr<const Function<Bool> > BoolFunctionPtr;
 	
 	Conditional(
 		const BoolFunctionPtr& cond_expr,
 		const ArgFunctionPtr& iftrue_expr,
-		const ArgFunctionPtr& iffalse_expr = detail::DefaultFunction<T>())
+		const ArgFunctionPtr& iffalse_expr = Default())
 		: cond_expr_(cond_expr), iftrue_expr_(iftrue_expr), iffalse_expr_(iffalse_expr)
 	{
 		BOOST_ASSERT(cond_expr_);
@@ -69,6 +69,10 @@ protected:
 		}
 		return iffalse_expr_->apply(context);
 	}
+private:
+	static const ArgFunctionPtr Default() {
+		return detail::DefaultFunction<T>();
+	}
 };
 
 /**
@@ -82,7 +86,7 @@ template<class T>
 class ConditionalOp : public Conditional<T> {
 public:
 	typedef typename Conditional<T>::ArgFunctionPtr ArgFunctionPtr;
-	typedef boost::shared_ptr<Function<Bool> > BoolFunctionPtr;
+	typedef typename Conditional<T>::BoolFunctionPtr BoolFunctionPtr;
 
 	ConditionalOp(
 		const BoolFunctionPtr& cond_expr,
diff --git a/libwccl/ops/functions/constant.h b/libwccl/ops/functions/constant.h
index 6ab8398..4f298e3 100644
--- a/libwccl/ops/functions/constant.h
+++ b/libwccl/ops/functions/constant.h
@@ -68,7 +68,7 @@ namespace detail {
  * that is returning default Value of given type T.
  */
 template<class T>
-static boost::shared_ptr<Function<T> > DefaultFunction() {
+static const boost::shared_ptr<const Function<T> > DefaultFunction() {
 	static boost::shared_ptr<Function<T> > default_fun(new Constant<T>((T())));
 	return default_fun;
 }
diff --git a/libwccl/ops/operator.h b/libwccl/ops/operator.h
index 767f958..f759ec6 100644
--- a/libwccl/ops/operator.h
+++ b/libwccl/ops/operator.h
@@ -53,7 +53,7 @@ template <class T>
 class Operator : public FunctionalOperator
 {
 public:
-	Operator(const boost::shared_ptr<Function<T> >& body, const Variables& variables);
+	Operator(const boost::shared_ptr<const Function<T> >& body, const Variables& variables);
 
 	/**
 	 * Applies the functional operator to given sentence context.
@@ -209,7 +209,7 @@ protected:
 	Operator* clone_internal() const;
 
 private:
-	boost::shared_ptr<Function<T> > function_body_;
+	boost::shared_ptr<Function<const T> > function_body_;
 };
 
 //--- implementation details ---
-- 
GitLab