Skip to content
Snippets Groups Projects
Commit 1f896e2a authored by Simon Praetorius's avatar Simon Praetorius Committed by Christoph Grüninger
Browse files

Fix constructors in iterators

parent 43a98e67
No related branches found
No related tags found
1 merge request!584Fix constructors in iterators
Pipeline #73730 passed
......@@ -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. */
......
......@@ -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. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment