diff --git a/dune/istl/basearray.hh b/dune/istl/basearray.hh index ffa8dc963181d5b493b906865923a2f5f5e45be4..48492a671c6e177b16f003522f9490ac33c01abb 100644 --- a/dune/istl/basearray.hh +++ b/dune/istl/basearray.hh @@ -10,6 +10,7 @@ #include <cstddef> #include <memory> #include <algorithm> +#include <type_traits> #include "istlexception.hh" #include <dune/common/iteratorfacades.hh> @@ -97,17 +98,27 @@ namespace Imp { friend class RealIterator<ValueType>; //! constructor - RealIterator () - : p(0), i(0) - {} + RealIterator () = default; - RealIterator (const B* _p, B* _i) : p(_p), i(_i) - { } + RealIterator (const B* _p, B* _i) + : p(_p), i(_i) + {} - RealIterator(const RealIterator<ValueType>& it) - : p(it.p), i(it.i) + template <class T_, + std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>, int> = 0> + RealIterator (const RealIterator<T_>& other) + : p(other.p), i(other.i) {} + template <class T_, + std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>, int> = 0> + RealIterator& operator= (const RealIterator<T_>& other) + { + p = other.p; + i = other.i; + return *this; + } + //! return index size_type index () const { @@ -163,8 +174,8 @@ namespace Imp { i+=d; } - const B* p; - B* i; + const B* p = nullptr; + B* i = nullptr; }; //! iterator type for sequential access @@ -349,22 +360,29 @@ namespace Imp { friend class RealIterator<ValueType>; //! constructor - RealIterator () - : p(0), j(0), i(0) - {} + RealIterator () = default; //! constructor RealIterator (B* _p, size_type* _j, size_type _i) : p(_p), j(_j), i(_i) - { } + {} - /** - * @brief Copy constructor from mutable iterator - */ - RealIterator(const RealIterator<ValueType>& it) - : p(it.p), j(it.j), i(it.i) + template <class T_, + std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>, int> = 0> + RealIterator (const RealIterator<T_>& other) + : p(other.p), j(other.j), i(other.i) {} + template <class T_, + std::enable_if_t<std::is_same_v<std::remove_const_t<T>, std::remove_const_t<T_>>, int> = 0> + RealIterator& operator= (const RealIterator<T_>& other) + { + p = other.p; + j = other.j; + i = other.i; + return *this; + } + //! equality bool equals (const RealIterator<ValueType>& it) const @@ -424,9 +442,9 @@ namespace Imp { return p[i]; } - B* p; - size_type* j; - size_type i; + B* p = nullptr; + size_type* j = nullptr; + size_type i = 0; }; /** @brief The iterator type. */ diff --git a/dune/istl/paamg/hierarchy.hh b/dune/istl/paamg/hierarchy.hh index 7d3e5a42c41f25e09734ff2ad1566efbe829bc43..e3f8d82347ceff3d7920a9cb607e001a8bfe3ef2 100644 --- a/dune/istl/paamg/hierarchy.hh +++ b/dune/istl/paamg/hierarchy.hh @@ -125,24 +125,28 @@ namespace Dune public: /** @brief Constructor. */ - LevelIterator() - {} + LevelIterator() = default; LevelIterator(std::shared_ptr<Element> element) - : element_(element) + : element_(std::move(element)) {} /** @brief Copy constructor. */ - LevelIterator(const LevelIterator<typename std::remove_const<C>::type, - typename std::remove_const<T1>::type>& other) + template <class C_, class T1_, + std::enable_if_t<std::is_same_v<std::remove_const_t<C>, std::remove_const_t<C_>>, int> = 0, + std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T1_>>, int> = 0> + LevelIterator(const LevelIterator<C_,T1_>& other) : element_(other.element_) {} - /** @brief Copy constructor. */ - LevelIterator(const LevelIterator<const typename std::remove_const<C>::type, - const typename std::remove_const<T1>::type>& other) - : element_(other.element_) - {} + template <class C_, class T1_, + std::enable_if_t<std::is_same_v<std::remove_const_t<C>, std::remove_const_t<C_>>, int> = 0, + std::enable_if_t<std::is_same_v<std::remove_const_t<T1>, std::remove_const_t<T1_>>, int> = 0> + LevelIterator& operator=(const LevelIterator<C_,T1_>& other) + { + element_ = other.element_; + return *this; + } /** * @brief Equality check. @@ -209,7 +213,7 @@ namespace Dune } private: - std::shared_ptr<Element> element_; + std::shared_ptr<Element> element_ = {}; }; /** @brief Type of the mutable iterator. */