Commit 3999d792 by Maarten L. Hekkelman

const iterator construction from non-const iterator

parent 4db37327
...@@ -144,7 +144,7 @@ class category_t ...@@ -144,7 +144,7 @@ class category_t
, m_columns(rhs.m_columns) , m_columns(rhs.m_columns)
{ {
for (auto r = rhs.m_head; r != nullptr; r = r->m_next) for (auto r = rhs.m_head; r != nullptr; r = r->m_next)
insert_impl(cend(), clone_row(*r)); insert_impl(end(), clone_row(*r));
} }
category_t(category_t &&rhs) category_t(category_t &&rhs)
......
...@@ -55,7 +55,10 @@ class iterator_impl ...@@ -55,7 +55,10 @@ class iterator_impl
using pointer = std::conditional_t<N == 0, row_handle_type, value_type *>; using pointer = std::conditional_t<N == 0, row_handle_type, value_type *>;
using reference = std::conditional_t<N == 0, row_handle_type, value_type &>; using reference = std::conditional_t<N == 0, row_handle_type, value_type &>;
iterator_impl(const iterator_impl &rhs) iterator_impl(const iterator_impl &rhs) = default;
template<typename C2, typename... T2s>
iterator_impl(const iterator_impl<C2, T2s...> &rhs)
: m_category(rhs.m_category) : m_category(rhs.m_category)
, m_current(rhs.m_current) , m_current(rhs.m_current)
, m_value(rhs.m_value) , m_value(rhs.m_value)
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
namespace cif::v2 namespace cif::v2
{ {
template<typename> class row_handle; template <typename>
class row_handle;
namespace detail namespace detail
{ {
...@@ -39,8 +40,7 @@ namespace detail ...@@ -39,8 +40,7 @@ namespace detail
// some helper classes to help create tuple result types // some helper classes to help create tuple result types
template < template <
typename Category, typename Category,
typename... C typename... C>
>
struct get_row_result struct get_row_result
{ {
using category_type = Category; using category_type = Category;
...@@ -102,7 +102,7 @@ namespace detail ...@@ -102,7 +102,7 @@ namespace detail
std::tuple<Ts...> m_value; std::tuple<Ts...> m_value;
}; };
} } // namespace detail
template <typename... Ts> template <typename... Ts>
auto tie(Ts &...v) auto tie(Ts &...v)
...@@ -113,14 +113,16 @@ auto tie(Ts &...v) ...@@ -113,14 +113,16 @@ auto tie(Ts &...v)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
/// \brief row_handle is the way to access data in rows /// \brief row_handle is the way to access data in rows
template<typename Category> template <typename Category>
class row_handle class row_handle
{ {
public: public:
using category_type = Category; using category_type = Category;
using row_type = std::conditional_t<std::is_const_v<category_type>, const typename category_type::row, typename category_type::row>; using row_type = std::conditional_t<std::is_const_v<category_type>, const typename category_type::row, typename category_type::row>;
template <typename>
friend class row_handle;
row_handle() = default; row_handle() = default;
row_handle(const row_handle &) = default; row_handle(const row_handle &) = default;
...@@ -129,10 +131,18 @@ class row_handle ...@@ -129,10 +131,18 @@ class row_handle
row_handle &operator=(const row_handle &) = default; row_handle &operator=(const row_handle &) = default;
row_handle &operator=(row_handle &&) = default; row_handle &operator=(row_handle &&) = default;
template <typename C2>
row_handle(const row_handle<C2> &rhs)
: m_cat(rhs.m_cat)
, m_row(rhs.m_row)
{
}
row_handle(category_type &cat, row_type &row) row_handle(category_type &cat, row_type &row)
: m_cat(&cat) : m_cat(&cat)
, m_row(&row) {} , m_row(&row)
{
}
explicit operator bool() const explicit operator bool() const
{ {
...@@ -177,7 +187,6 @@ class row_handle ...@@ -177,7 +187,6 @@ class row_handle
} }
private: private:
uint32_t get_column_ix(std::string_view name) const uint32_t get_column_ix(std::string_view name) const
{ {
return m_cat->get_column_ix(name); return m_cat->get_column_ix(name);
...@@ -187,5 +196,4 @@ class row_handle ...@@ -187,5 +196,4 @@ class row_handle
row_type *m_row = nullptr; row_type *m_row = nullptr;
}; };
} // namespace cif::v2
} \ No newline at end of file
\ No newline at end of file
...@@ -240,6 +240,28 @@ BOOST_AUTO_TEST_CASE(c_2) ...@@ -240,6 +240,28 @@ BOOST_AUTO_TEST_CASE(c_2)
BOOST_CHECK_EQUAL(c.size(), 3); BOOST_CHECK_EQUAL(c.size(), 3);
} }
BOOST_AUTO_TEST_CASE(ci_1)
{
cif::v2::category c("foo");
c.emplace({{"id", 1}, {"s", "aap"}});
c.emplace({{"id", 2}, {"s", "noot"}});
c.emplace({{"id", 3}, {"s", "mies"}});
cif::v2::category::iterator i1 = c.begin();
cif::v2::category::const_iterator i2 = c.cbegin();
cif::v2::category::const_iterator i3 = c.begin();
cif::v2::category::const_iterator i4 = i2;
cif::v2::category::const_iterator i5 = i1;
BOOST_CHECK(i1 == i2);
BOOST_CHECK(i1 == i3);
BOOST_CHECK(i1 == i4);
BOOST_CHECK(i1 == i5);
}
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// BOOST_AUTO_TEST_CASE(f_1) // BOOST_AUTO_TEST_CASE(f_1)
......
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