3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-21 13:23:39 +00:00

Add dll_elements

This commit is contained in:
Jakob Rath 2023-07-27 15:31:06 +02:00
parent edbe1087e3
commit 305943a091

View file

@ -188,14 +188,14 @@ class dll_iterator {
dll_iterator(T const* elem, bool first): m_elem(elem), m_first(first) { } dll_iterator(T const* elem, bool first): m_elem(elem), m_first(first) { }
public: public:
static dll_iterator mk_begin(T const* elem) { static dll_iterator mk_begin(T const* list) {
// Setting first==(bool)elem makes this also work for elem==nullptr; // Setting first==(bool)list makes this also work for list==nullptr;
// but we can't implement top-level begin/end for pointers because it clashes with the definition for arrays. // but we can't implement top-level begin/end for pointers because it clashes with the definition for arrays.
return {elem, (bool)elem}; return {list, (bool)list};
} }
static dll_iterator mk_end(T const* elem) { static dll_iterator mk_end(T const* list) {
return {elem, false}; return {list, false};
} }
using value_type = T; using value_type = T;
@ -226,14 +226,23 @@ public:
template < typename T template < typename T
, typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T> , typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T>
> >
dll_iterator<T> begin(T const& elem) { dll_iterator<T> begin(T const& list) {
return dll_iterator<T>::mk_begin(&elem); return dll_iterator<T>::mk_begin(&list);
} }
template < typename T template < typename T
, typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T> , typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T>
> >
dll_iterator<T> end(T const& elem) dll_iterator<T> end(T const& list)
{ {
return dll_iterator<T>::mk_end(&elem); return dll_iterator<T>::mk_end(&list);
} }
template <typename T>
class dll_elements {
T const* m_list;
public:
dll_elements(T const* list): m_list(list) {}
dll_iterator<T> begin() const { return dll_iterator<T>::mk_begin(m_list); }
dll_iterator<T> end() const { return dll_iterator<T>::mk_end(m_list); }
};