diff --git a/src/json.hpp b/src/json.hpp index 3aad611b..89269ea3 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2072,11 +2072,22 @@ class basic_json } } + /// copy constructor + inline iterator(const iterator& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + /// copy assignment - inline iterator& operator=(const iterator& other) noexcept + inline iterator& operator=(iterator other) noexcept ( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible>::value + and + std::is_nothrow_move_assignable>::value + ) { - m_object = other.m_object; - m_it = other.m_it; + std::swap(m_object, other.m_object); + std::swap(m_it, other.m_it); return *this; } @@ -2575,11 +2586,22 @@ class basic_json } } + /// copy constructor + inline const_iterator(const const_iterator& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + /// copy assignment - inline const_iterator& operator=(const const_iterator& other) noexcept + inline const_iterator& operator=(const_iterator other) noexcept( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible>::value + and + std::is_nothrow_move_assignable>::value + ) { - m_object = other.m_object; - m_it = other.m_it; + std::swap(m_object, other.m_object); + std::swap(m_it, other.m_it); return *this; } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 0829e9b1..5ebda5a7 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2072,11 +2072,22 @@ class basic_json } } + /// copy constructor + inline iterator(const iterator& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + /// copy assignment - inline iterator& operator=(const iterator& other) noexcept + inline iterator& operator=(iterator other) noexcept ( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible>::value + and + std::is_nothrow_move_assignable>::value + ) { - m_object = other.m_object; - m_it = other.m_it; + std::swap(m_object, other.m_object); + std::swap(m_it, other.m_it); return *this; } @@ -2575,11 +2586,22 @@ class basic_json } } + /// copy constructor + inline const_iterator(const const_iterator& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + /// copy assignment - inline const_iterator& operator=(const const_iterator& other) noexcept + inline const_iterator& operator=(const_iterator other) noexcept( + std::is_nothrow_move_constructible::value and + std::is_nothrow_move_assignable::value and + std::is_nothrow_move_constructible>::value + and + std::is_nothrow_move_assignable>::value + ) { - m_object = other.m_object; - m_it = other.m_it; + std::swap(m_object, other.m_object); + std::swap(m_it, other.m_it); return *this; }