From cee495cac80ac9b778530943115a3172128ebf8a Mon Sep 17 00:00:00 2001
From: Sam Yates <halfflat@gmail.com>
Date: Fri, 28 Oct 2016 11:09:30 +0200
Subject: [PATCH] Address PR#46 review comments.

* Add documentation of template parameters for `filter_iterator`.
* Document use of `uninitalized<F>` for holding functional objects
  in `filter_iterator` and `transform_iterator`
---
 src/util/filter.hpp    | 19 ++++++++++++++++++-
 src/util/transform.hpp |  5 ++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/util/filter.hpp b/src/util/filter.hpp
index 5fcbd1fd..6da37f57 100644
--- a/src/util/filter.hpp
+++ b/src/util/filter.hpp
@@ -32,12 +32,29 @@ namespace impl {
     };
 }
 
+/*
+ * Iterate through a sequence such that dereference only
+ * gives items from the range that satisfy a given predicate.
+ *
+ * Type parameters:
+ *     I      Iterator type
+ *     S      Sentinel type compatible with I
+ *     F      Functional object
+ *
+ * The underlying sequence is described by an iterator of type
+ * I and a sentinel of type S. The predicate has type F.
+ */
+
 template <typename I, typename S, typename F>
 class filter_iterator {
     mutable I inner_;
     S end_;
     mutable bool ok_;
-    mutable uninitialized<F> f_; // always in initialized state post-construction
+
+    // F may be a lambda type, and thus non-copy assignable. The
+    // use of `uninitalized` allows us to work around this limitation;
+    // f_ will always be in an initalized state post-construction.
+    mutable uninitialized<F> f_;
 
     void advance() const {
         if (ok_) return;
diff --git a/src/util/transform.hpp b/src/util/transform.hpp
index ec86ea71..71c49e72 100644
--- a/src/util/transform.hpp
+++ b/src/util/transform.hpp
@@ -26,7 +26,10 @@ class transform_iterator: public iterator_adaptor<transform_iterator<I, F>, I> {
     friend class iterator_adaptor<transform_iterator<I, F>, I>;
 
     I inner_;
-    uninitialized<F> f_; // always in initialized state post-construction
+
+    // F may be a lambda type, and thus non-copy assignable. The
+    // use of `uninitalized` allows us to work around this limitation;
+    uninitialized<F> f_;
 
     // provides access to inner iterator for adaptor.
     const I& inner() const { return inner_; }
-- 
GitLab