diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 72ca639db..38cc32aa3 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -237,21 +237,25 @@ protected: IncrType m_incr; }; +namespace internal { + template struct cleanup_seq_type { typedef T type; }; template struct cleanup_seq_type::value>::type> { typedef Index type; }; template struct cleanup_seq_type > { typedef fix_t type; }; template struct cleanup_seq_type (*)() > { typedef fix_t type; }; +} + template -ArithemeticSequence::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type > +ArithemeticSequence::type,typename internal::cleanup_seq_type::type,typename internal::cleanup_seq_type::type > seqN(FirstType first, SizeType size, IncrType incr) { - return ArithemeticSequence::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type>(first,size,incr); + return ArithemeticSequence::type,typename internal::cleanup_seq_type::type,typename internal::cleanup_seq_type::type>(first,size,incr); } template -ArithemeticSequence::type,typename cleanup_seq_type::type > +ArithemeticSequence::type,typename internal::cleanup_seq_type::type > seqN(FirstType first, SizeType size) { - return ArithemeticSequence::type,typename cleanup_seq_type::type>(first,size); + return ArithemeticSequence::type,typename internal::cleanup_seq_type::type>(first,size); } #if EIGEN_HAS_CXX11 @@ -263,15 +267,16 @@ auto seq(FirstType f, LastType l) -> decltype(seqN(f,(l-f+fix<1>()))) template auto seq(FirstType f, LastType l, IncrType incr) - -> decltype(seqN(f,(l-f+typename cleanup_seq_type::type(incr))/typename cleanup_seq_type::type(incr),typename cleanup_seq_type::type(incr))) + -> decltype(seqN(f, (l-f+typename internal::cleanup_seq_type::type(incr)) + / typename internal::cleanup_seq_type::type(incr),typename internal::cleanup_seq_type::type(incr))) { - typedef typename cleanup_seq_type::type CleanedIncrType; + typedef typename internal::cleanup_seq_type::type CleanedIncrType; return seqN(f,(l-f+CleanedIncrType(incr))/CleanedIncrType(incr),CleanedIncrType(incr)); } #else template typename internal::enable_if::value || Symbolic::is_symbolic::value), - ArithemeticSequence::type,Index> >::type + ArithemeticSequence::type,Index> >::type seq(FirstType f, LastType l) { return seqN(f,(l-f+1)); @@ -288,7 +293,7 @@ seq(const Symbolic::BaseExpr &f, LastType l) template typename internal::enable_if::value, - ArithemeticSequence::type, + ArithemeticSequence::type, Symbolic::AddExpr,Symbolic::ValueExpr> > >::type seq(FirstType f, const Symbolic::BaseExpr &l) { @@ -306,10 +311,10 @@ seq(const Symbolic::BaseExpr &f, const Symbolic::BaseExpr typename internal::enable_if::value || Symbolic::is_symbolic::value), - ArithemeticSequence::type,Index,typename cleanup_seq_type::type> >::type + ArithemeticSequence::type,Index,typename internal::cleanup_seq_type::type> >::type seq(FirstType f, LastType l, IncrType incr) { - typedef typename cleanup_seq_type::type CleanedIncrType; + typedef typename internal::cleanup_seq_type::type CleanedIncrType; return seqN(f,(l-f+CleanedIncrType(incr))/CleanedIncrType(incr), incr); } @@ -320,23 +325,23 @@ typename internal::enable_if::value, Symbolic::ValueExpr>, Symbolic::ValueExpr>, Symbolic::ValueExpr>, - typename cleanup_seq_type::type> >::type + typename internal::cleanup_seq_type::type> >::type seq(const Symbolic::BaseExpr &f, LastType l, IncrType incr) { - typedef typename cleanup_seq_type::type CleanedIncrType; + typedef typename internal::cleanup_seq_type::type CleanedIncrType; return seqN(f.derived(),(l-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); } template typename internal::enable_if::value, - ArithemeticSequence::type, + ArithemeticSequence::type, Symbolic::QuotientExpr, Symbolic::ValueExpr>, Symbolic::ValueExpr>, - typename cleanup_seq_type::type> >::type + typename internal::cleanup_seq_type::type> >::type seq(FirstType f, const Symbolic::BaseExpr &l, IncrType incr) { - typedef typename cleanup_seq_type::type CleanedIncrType; + typedef typename internal::cleanup_seq_type::type CleanedIncrType; return seqN(f,(l.derived()-f+CleanedIncrType(incr))/CleanedIncrType(incr), incr); } @@ -346,10 +351,10 @@ ArithemeticSequence >, Symbolic::ValueExpr>, Symbolic::ValueExpr>, - typename cleanup_seq_type::type> + typename internal::cleanup_seq_type::type> seq(const Symbolic::BaseExpr &f, const Symbolic::BaseExpr &l, IncrType incr) { - typedef typename cleanup_seq_type::type CleanedIncrType; + typedef typename internal::cleanup_seq_type::type CleanedIncrType; return seqN(f.derived(),(l.derived()-f.derived()+CleanedIncrType(incr))/CleanedIncrType(incr), incr); } #endif @@ -423,13 +428,13 @@ struct MakeIndexing::val }; // Replace symbolic last/end "keywords" by their true runtime value -Index symbolic2value(Index x, Index /* size */) { return x; } +Index eval_expr_given_size(Index x, Index /* size */) { return x; } template -fix_t symbolic2value(fix_t x, Index /*size*/) { return x; } +fix_t eval_expr_given_size(fix_t x, Index /*size*/) { return x; } template -Index symbolic2value(const Symbolic::BaseExpr &x, Index size) +Index eval_expr_given_size(const Symbolic::BaseExpr &x, Index size) { return x.derived().eval(Symbolic::defineValue(placeholders::last,size-1)); } @@ -449,7 +454,7 @@ template ArithemeticSequence::type,IncrType> make_indexing(const ArithemeticSequence& ids, Index size) { return ArithemeticSequence::type,IncrType>( - symbolic2value(ids.firstObject(),size),symbolic2value(ids.sizeObject(),size),ids.incrObject()); + eval_expr_given_size(ids.firstObject(),size),eval_expr_given_size(ids.sizeObject(),size),ids.incrObject()); } // Convert a symbolic 'all' into a usable range @@ -522,10 +527,10 @@ struct end_t { }; static const end_t end; -Index symbolic2value(last_t, Index size) { return size-1; } -Index symbolic2value(shifted_last x, Index size) { return size+x.offset-1; } -Index symbolic2value(end_t, Index size) { return size; } -Index symbolic2value(shifted_end x, Index size) { return size+x.offset; } +Index eval_expr_given_size(last_t, Index size) { return size-1; } +Index eval_expr_given_size(shifted_last x, Index size) { return size+x.offset-1; } +Index eval_expr_given_size(end_t, Index size) { return size; } +Index eval_expr_given_size(shifted_end x, Index size) { return size+x.offset; } template > class ArithemeticSequenceProxyWithBounds @@ -553,15 +558,21 @@ protected: }; template -ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type > +ArithemeticSequenceProxyWithBounds::type,typename internal::cleanup_seq_type::type > seq(FirstType f, LastType l) { - return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type>(f,l); + return ArithemeticSequenceProxyWithBounds::type,typename internal::cleanup_seq_type::type>(f,l); } template -ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type > -seq(FirstType f, LastType l, IncrType s) { - return ArithemeticSequenceProxyWithBounds::type,typename cleanup_seq_type::type,typename cleanup_seq_type::type>(f,l,typename cleanup_seq_type::type(s)); +ArithemeticSequenceProxyWithBounds< typename internal::cleanup_seq_type::type, + typename internal::cleanup_seq_type::type, + typename internal::cleanup_seq_type::type > +seq(FirstType f, LastType l, IncrType s) +{ + return ArithemeticSequenceProxyWithBounds::type, + typename internal::cleanup_seq_type::type, + typename internal::cleanup_seq_type::type> + (f,l,typename internal::cleanup_seq_type::type(s)); } } @@ -583,7 +594,7 @@ template legacy::ArithemeticSequenceProxyWithBounds make_indexing(const legacy::ArithemeticSequenceProxyWithBounds& ids, Index size) { return legacy::ArithemeticSequenceProxyWithBounds( - symbolic2value(ids.firstObject(),size),symbolic2value(ids.lastObject(),size),ids.incrObject()); + eval_expr_given_size(ids.firstObject(),size),eval_expr_given_size(ids.lastObject(),size),ids.incrObject()); } }