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

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.
parent a84919bb
No related merge requests found
......@@ -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
......
......@@ -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 */
......
......@@ -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())),
......
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