Merged in ezhulenev/eigen-01 (pull request PR-523)

Compile time detection for unimplemented stl-style iterators
This commit is contained in:
Rasmus Munk Larsen
2018-10-09 23:42:01 +00:00
4 changed files with 83 additions and 1 deletions

View File

@@ -583,11 +583,23 @@ template<typename Derived> class DenseBase
typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
internal::pointer_based_stl_iterator<Derived>,
internal::generic_randaccess_stl_iterator<Derived>
>::type iterator;
>::type iterator_type;
typedef typename internal::conditional< (Flags&DirectAccessBit)==DirectAccessBit,
internal::pointer_based_stl_iterator<const Derived>,
internal::generic_randaccess_stl_iterator<const Derived>
>::type const_iterator_type;
// Stl-style iterators are supported only for vectors.
typedef typename internal::conditional< IsVectorAtCompileTime,
iterator_type,
internal::not_an_iterator<const Derived>
>::type iterator;
typedef typename internal::conditional< IsVectorAtCompileTime,
const_iterator_type,
internal::not_an_iterator<const Derived>
>::type const_iterator;
#endif

View File

@@ -11,6 +11,19 @@ namespace Eigen {
namespace internal {
// Iterator type for XprType that do not support stl-style iterators. Allows to
// detect that expression does not support stl iterators at compile time.
template<typename XprType>
class not_an_iterator
{
not_an_iterator() : mp_xpr(0), m_index(0) {}
not_an_iterator(XprType& xpr, Index index) : mp_xpr(&xpr), m_index(index) {}
protected:
XprType *mp_xpr;
Index m_index;
};
template<typename XprType,typename Derived>
class indexed_based_stl_iterator_base
{

View File

@@ -135,6 +135,7 @@ template<typename Derived> class SolverBase;
template<typename XprType> class InnerIterator;
namespace internal {
template<typename XprType> class not_an_iterator;
template<typename XprType> class generic_randaccess_stl_iterator;
template<typename XprType> class pointer_based_stl_iterator;
template<typename XprType, DirectionType Direction> class subvector_stl_iterator;