Commit 0269a0c9 authored by Praetorius, Simon's avatar Praetorius, Simon

Merge branch 'issue/expressions' into 'dev'

small updates in simplify and functor expressions

See merge request !26
parents 383830fc a6df9bdc
......@@ -109,13 +109,13 @@ namespace AMDiS
template <class R, class C, class... As>
struct Function<R (C::*)(As...)>
{
typedef R result_type;
typedef R type;
};
template<class R, class C, class... As>
struct Function<R (C::*)(As...) const>
{
typedef R type;
typedef R type;
};
template <class T>
......@@ -128,11 +128,6 @@ namespace AMDiS
typedef decltype(function_helper(&F::operator())) type;
};
template <class R, class... As>
struct Functor<std::function<R(As...)> >
{
typedef R type;
};
template <class F>
struct Functor<F, typename void_<typename F::value_type>::type>
......
......@@ -74,6 +74,16 @@ namespace AMDiS
static type eval(RValue<T> const& t) { return t; }
};
/// -(n) -> (-n)
template<class T>
struct Simplify< Negative<RValue<T> > >
{
typedef RValue<T> type;
static type eval(Negative<RValue<T> > const& t)
{ return RValue<T>(-t.term.value); }
};
/// -(N) -> (-N)
template<int N>
struct Simplify< Negative<CValue<N> > >
......@@ -82,7 +92,6 @@ namespace AMDiS
static type eval(Negative<CValue<N> > const& t)
{ return CValue<-N>(); }
};
/// -0 -> 0
......@@ -439,14 +448,23 @@ namespace AMDiS
/// (X + (-Y)) -> X - Y
template<typename X, typename Y>
struct Simplify< Negative<Add<X, Negative<Y> > > >
struct Simplify< Add<X, Negative<Y> > >
{
typedef Subtract<X, Y> type;
static type eval(Negative<Add<X, Negative<Y> > > const& t)
static type eval(Add<X, Negative<Y> > const& t)
{ return t.term1 - t.term2.term; }
};
template<typename Y>
struct Simplify< Add<CValue<0>, Negative<Y> > >
{
typedef Negative<Y> type;
static type eval(Add<CValue<0>, Negative<Y> > const& t)
{ return t.term2; }
};
/// -(X - Y) -> Y - X
template<typename X, typename Y>
struct Simplify< Negative<Subtract<X, Y> > >
......
Markdown is supported
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