Commit 753723c6 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: simplify VectorSpaceOps template looping

- this is a continuation of commit 39d8a9e6 with simpler
  template logic.
parent 6cb6677d
......@@ -39,42 +39,29 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- General looping form. Executing at index \<I\> with termination at \<N\>
template<direction N, direction I>
class VectorSpaceOps
struct VectorSpaceOps
{
public:
//- End for next loop. Is 0 for loop termination.
static constexpr direction loopN() noexcept
{
return (I+1 < N) ? N : 0;
}
//- Index for next loop. Is 0 for loop termination.
static constexpr direction loopI1() noexcept
{
return (I+1 < N) ? I+1 : 0;
}
template<class V, class S, class EqOp>
static inline void eqOpS(V& vs, const S& s, EqOp eo)
{
eo(vs.v_[I], s);
VectorSpaceOps<loopN(), loopI1()>::eqOpS(vs, s, eo);
VectorSpaceOps<N, I+1>::eqOpS(vs, s, eo);
}
template<class S, class V, class EqOp>
static inline void SeqOp(S& s, const V& vs, EqOp eo)
{
eo(s, vs.v_[I]);
VectorSpaceOps<loopN(), loopI1()>::SeqOp(s, vs, eo);
VectorSpaceOps<N, I+1>::SeqOp(s, vs, eo);
}
template<class V1, class V2, class EqOp>
static inline void eqOp(V1& vs1, const V2& vs2, EqOp eo)
{
eo(vs1.v_[I], vs2.v_[I]);
VectorSpaceOps<loopN(), loopI1()>::eqOp(vs1, vs2, eo);
VectorSpaceOps<N, I+1>::eqOp(vs1, vs2, eo);
}
......@@ -82,55 +69,46 @@ public:
static inline void opVS(V& vs, const V1& vs1, const S& s, Op o)
{
vs.v_[I] = o(vs1.v_[I], s);
VectorSpaceOps<loopN(), loopI1()>::opVS(vs, vs1, s, o);
VectorSpaceOps<N, I+1>::opVS(vs, vs1, s, o);
}
template<class V, class S, class V1, class Op>
static inline void opSV(V& vs, const S& s, const V1& vs1, Op o)
{
vs.v_[I] = o(s, vs1.v_[I]);
VectorSpaceOps<loopN(), loopI1()>::opSV(vs, s, vs1, o);
VectorSpaceOps<N, I+1>::opSV(vs, s, vs1, o);
}
template<class V, class V1, class Op>
static inline void op(V& vs, const V1& vs1, const V1& vs2, Op o)
{
vs.v_[I] = o(vs1.v_[I], vs2.v_[I]);
VectorSpaceOps<loopN(), loopI1()>::op(vs, vs1, vs2, o);
VectorSpaceOps<N, I+1>::op(vs, vs1, vs2, o);
}
};
//- Specialization for loop termination of vector space ops
template<>
class VectorSpaceOps<0, 0>
//- Loop termination form, when index and loop count \<N\> are identical
template<direction N>
struct VectorSpaceOps<N, N>
{
public:
template<class V, class S, class EqOp>
static inline void eqOpS(V&, const S&, EqOp)
{}
static inline void eqOpS(V&, const S&, EqOp) {}
template<class S, class V, class EqOp>
static inline void SeqOp(S&, const V&, EqOp)
{}
static inline void SeqOp(S&, const V&, EqOp) {}
template<class V1, class V2, class EqOp>
static inline void eqOp(V1&, const V2&, EqOp)
{}
static inline void eqOp(V1&, const V2&, EqOp) {}
template<class V, class V1, class S, class Op>
static inline void opVS(V& vs, const V1&, const S&, Op)
{}
static inline void opVS(V& vs, const V1&, const S&, Op) {}
template<class V, class S, class V1, class Op>
static inline void opSV(V& vs, const S&, const V1&, Op)
{}
static inline void opSV(V& vs, const S&, const V1&, Op) {}
template<class V, class V1, class Op>
static inline void op(V& vs, const V1&, const V1&, Op)
{}
static inline void op(V& vs, const V1&, const V1&, Op) {}
};
......
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