diff --git a/libwccl/ops/functions/conditional.h b/libwccl/ops/functions/conditional.h index 763339c887b3f79ae5c4c1c9de1476209ed230a1..af07a740b719e2426d866a6cf217fa4d9a92d68b 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 6ab839889243e5105f10edb5697075d33adb3159..4f298e3701fd3b0c9456a669212f76b0f72b7780 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 767f95815856473eb926059646f1d982202d8013..f759ec63b23e3831a1e4b354ce72c924f6636337 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 ---