Commit ce39330f authored by HenryLee's avatar HenryLee

Add converting constructors for iterator

parent 52adf3fd
...@@ -8053,42 +8053,58 @@ class basic_json ...@@ -8053,42 +8053,58 @@ class basic_json
} }
} }
/* /*!
Use operator `const_iterator` instead of `const_iterator(const iterator& @note The conventional copy constructor is not defined. It is replaced
other) noexcept` to avoid two class definitions for @ref iterator and by either of the following two converting constructors.
@ref const_iterator. They support copy from iterator to iterator,
copy from const iterator to const iterator,
This function is only called if this class is an @ref iterator. If this and conversion from iterator to const iterator.
class is a @ref const_iterator this function is not called. However conversion from const iterator to iterator is not defined.
*/ */
operator const_iterator() const
{
const_iterator ret;
if (m_object)
{
ret.m_object = m_object;
ret.m_it = m_it;
}
return ret; /*!
} @brief converting constructor
@param[in] other non-const iterator to copy from
@note It is not checked whether @a other is initialized.
*/
iter_impl(const iter_impl<basic_json>& other) noexcept
: m_object(other.m_object), m_it(other.m_it)
{}
/*! /*!
@brief copy constructor @brief converting constructor
@param[in] other iterator to copy from @param[in] other const iterator to copy from
@note It is not checked whether @a other is initialized. @note It is not checked whether @a other is initialized.
*/ */
iter_impl(const iter_impl& other) noexcept iter_impl<const basic_json>(const iter_impl<const basic_json>& other) noexcept
: m_object(other.m_object), m_it(other.m_it) : m_object(other.m_object), m_it(other.m_it)
{} {}
/*! /*!
@brief copy assignment @brief copy assignment
@param[in,out] other iterator to copy from @param[in,out] other non-const iterator to copy from
@return const/non-const iterator
@note It is not checked whether @a other is initialized.
*/
iter_impl& operator=(iter_impl<basic_json> other) noexcept(
std::is_nothrow_move_constructible<pointer>::value and
std::is_nothrow_move_assignable<pointer>::value and
std::is_nothrow_move_constructible<internal_iterator>::value and
std::is_nothrow_move_assignable<internal_iterator>::value
)
{
std::swap(m_object, other.m_object);
std::swap(m_it, other.m_it);
return *this;
}
/*!
@brief copy assignment
@param[in,out] other const iterator to copy from
@return const iterator
@note It is not checked whether @a other is initialized. @note It is not checked whether @a other is initialized.
*/ */
iter_impl& operator=(iter_impl other) noexcept( iter_impl<const basic_json>& operator=(iter_impl<const basic_json> other) noexcept(
std::is_nothrow_move_constructible<pointer>::value and std::is_nothrow_move_constructible<pointer>::value and
std::is_nothrow_move_assignable<pointer>::value and std::is_nothrow_move_assignable<pointer>::value and
std::is_nothrow_move_constructible<internal_iterator>::value and std::is_nothrow_move_constructible<internal_iterator>::value and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment