Skip to content
Snippets Groups Projects
Commit b67ecdd0 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Reworking DefaultFunction a bit, putting const.

parent e01ab872
Branches
No related merge requests found
......@@ -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,
......
......@@ -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;
}
......
......@@ -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 ---
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment