summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2016-08-30 01:31:23 +1000
committer Vas Crabb <vas@vastheman.com>2016-08-30 01:31:23 +1000
commit46bf1ce04bf75f7e5e613a993ac0cf1859b068ec (patch)
tree8e071c12fb7edfd77494d3cd97fbf154a87087c5 /src/lib
parent7c6a527e2630f9317e2941ea991e8d7df1282544 (diff)
More cleanup on the back of Osso's fix for a7e393b36b57cead61978f332135a509b2ddc82a (nw)
* Make iterators actually meet requirements of ForwardIterator (and by consequence, ForwardIterator, Iterator and EqualityComparable) * Don't use function statics if they can be avoided - it isn't thread-safe * Remove leftover crud from when dynamic_buffer and friends were templates in lib/util It's still dangerous that the const behaviour of iterators doesn't match STL. Also, simple_list members with similar functionality to STL container members should be renamed.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/coretmpl.h51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h
index c285f818b6a..b0e283378ed 100644
--- a/src/lib/util/coretmpl.h
+++ b/src/lib/util/coretmpl.h
@@ -16,14 +16,10 @@
#include "osdcore.h"
#include "corealloc.h"
+#include <iterator>
+#include <utility>
#include <vector>
-// TEMPORARY helper to catch is_pod assertions in the debugger
-#if 0
-#undef assert
-#define assert(x) do { if (!(x)) { fprintf(stderr, "Assert: %s\n", #x); osd_break_into_debugger("Assertion failed"); } } while (0)
-#endif
-
typedef std::vector<UINT8> dynamic_buffer;
@@ -38,32 +34,53 @@ class simple_list final
public:
class auto_iterator
{
-public:
+ public:
+ typedef int difference_type;
+ typedef _ElementType value_type;
+ typedef _ElementType *pointer;
+ typedef _ElementType &reference;
+ typedef std::forward_iterator_tag iterator_category;
+
// construction/destruction
+ auto_iterator() noexcept : m_current(nullptr) { }
auto_iterator(_ElementType *ptr) noexcept : m_current(ptr) { }
- // required operator overrides
+ // required operator overloads
+ bool operator==(const auto_iterator &iter) const noexcept { return m_current == iter.m_current; }
bool operator!=(const auto_iterator &iter) const noexcept { return m_current != iter.m_current; }
_ElementType &operator*() const noexcept { return *m_current; }
+ _ElementType *operator->() const noexcept { return m_current; }
// note that _ElementType::next() must not return a const ptr
- const auto_iterator &operator++() noexcept { m_current = m_current->next(); return *this; }
+ auto_iterator &operator++() noexcept { m_current = m_current->next(); return *this; }
+ auto_iterator operator++(int) noexcept { auto_iterator result(*this); m_current = m_current->next(); return result; }
-private:
+ private:
// private state
_ElementType *m_current;
};
+ // construction/destruction
+ simple_list() noexcept
+ : m_head(nullptr)
+ , m_tail(nullptr)
+ , m_count(0)
+ {
+ }
+ ~simple_list() noexcept { reset(); }
+
// we don't support deep copying
simple_list(const simple_list &) = delete;
simple_list &operator=(const simple_list &) = delete;
- // construction/destruction
- simple_list() noexcept
- : m_head(nullptr),
- m_tail(nullptr),
- m_count(0) { }
-
- ~simple_list() noexcept { reset(); }
+ // but we do support cheap swap/move
+ simple_list(simple_list &&list) : simple_list() { operator=(std::move(list)); }
+ simple_list &operator=(simple_list &&list)
+ {
+ using std::swap;
+ swap(m_head, list.m_head);
+ swap(m_tail, list.m_tail);
+ swap(m_count, list.m_count);
+ }
// simple getters
_ElementType *first() const noexcept { return m_head; }