aboutsummaryrefslogtreecommitdiff
path: root/libcutl/container/pointer-iterator.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-16 20:29:05 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-02-24 16:40:04 +0300
commit8e761289a2446367267c6c0d9a26e734f0f78306 (patch)
treefb495d8c18801f271d124ee48731f10df396ca89 /libcutl/container/pointer-iterator.hxx
parent4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff)
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/container/pointer-iterator.hxx')
-rw-r--r--libcutl/container/pointer-iterator.hxx125
1 files changed, 125 insertions, 0 deletions
diff --git a/libcutl/container/pointer-iterator.hxx b/libcutl/container/pointer-iterator.hxx
new file mode 100644
index 0000000..586e15b
--- /dev/null
+++ b/libcutl/container/pointer-iterator.hxx
@@ -0,0 +1,125 @@
+// file : libcutl/container/pointer-iterator.hxx
+// license : MIT; see accompanying LICENSE file
+
+#ifndef LIBCUTL_CONTAINER_POINTER_ITERATOR_HXX
+#define LIBCUTL_CONTAINER_POINTER_ITERATOR_HXX
+
+#include <iterator> // std::iterator_traits
+
+#include <libcutl/meta/remove-p.hxx>
+
+namespace cutl
+{
+ namespace container
+ {
+ template <typename I>
+ class pointer_iterator
+ {
+ public:
+ typedef
+ typename meta::remove_p<typename std::iterator_traits<I>::value_type>::r
+ value_type;
+
+ typedef
+ typename std::iterator_traits<I>::iterator_category
+ iterator_category;
+
+ typedef
+ typename std::iterator_traits<I>::difference_type
+ difference_type;
+
+ typedef value_type& reference;
+ typedef value_type* pointer;
+ typedef I base_iterator;
+
+ public:
+ pointer_iterator ()
+ : i_ () // I can be of a pointer type.
+ {
+ }
+
+ pointer_iterator (I const& i)
+ : i_ (i)
+ {
+ }
+
+ public:
+ reference
+ operator* () const
+ {
+ return **i_;
+ }
+
+ pointer
+ operator-> () const
+ {
+ return *i_;
+ }
+
+ I const&
+ base () const
+ {
+ return i_;
+ }
+
+ public:
+ // Forward iterator requirements.
+ //
+ pointer_iterator&
+ operator++ ()
+ {
+ ++i_;
+ return *this;
+ }
+
+ pointer_iterator
+ operator++ (int)
+ {
+ pointer_iterator r (*this);
+ ++i_;
+ return r;
+ }
+
+ pointer_iterator&
+ operator-- ()
+ {
+ --i_;
+ return *this;
+ }
+
+ pointer_iterator
+ operator-- (int)
+ {
+ pointer_iterator r (*this);
+ --i_;
+ return r;
+ }
+
+ private:
+ I i_;
+ };
+
+ template <typename I>
+ inline bool
+ operator== (pointer_iterator<I> const& a, pointer_iterator<I> const& b)
+ {
+ return a.base () == b.base ();
+ }
+
+ template <typename I>
+ inline bool
+ operator!= (pointer_iterator<I> const& a, pointer_iterator<I> const& b)
+ {
+ return a.base () != b.base ();
+ }
+
+ template <typename I>
+ inline typename pointer_iterator<I>::difference_type
+ operator- (pointer_iterator<I> const& a, pointer_iterator<I> const& b)
+ {
+ return a.base () - b.base ();
+ }
+ }
+}
+
+#endif // LIBCUTL_CONTAINER_POINTER_ITERATOR_HXX