Selaa lähdekoodia

refactor: add FWD(X) macro
refactor: delete sentinel_iterator as only used by ranges::common_view

Sam Jaffe 2 vuotta sitten
vanhempi
commit
b4916e3c4f

+ 7 - 3
include/iterator/detail/default_constructible_function_proxy.h

@@ -6,7 +6,9 @@
 //  Copyright © 2023 Sam Jaffe. All rights reserved.
 //
 
-#include <optional>include/iterator/detail/default_constructible_function_proxy.h
+#include <optional>
+
+#include <iterator/detail/macro.h>
 
 namespace iterator::detail {
 template <typename F, typename = void>
@@ -17,7 +19,7 @@ public:
 
   template <typename... Args> decltype(auto) operator()(Args &&... args) const {
     if (!func_) { throw; }
-    return std::invoke(*func_, std::forward<Args>(args)...);
+    return std::invoke(*func_, FWD(args)...);
   }
 
 private:
@@ -33,10 +35,12 @@ public:
   default_constructible_function_proxy(F func) : func_(func) {}
 
   template <typename... Args> decltype(auto) operator()(Args &&... args) const {
-    return std::invoke(func_, std::forward<Args>(args)...);
+    return std::invoke(func_, FWD(args)...);
   }
 
 private:
   F func_;
 };
 }
+
+#include <iterator/detail/undef.h>

+ 2 - 0
include/iterator/detail/macro.h

@@ -9,6 +9,8 @@
 #ifndef _ITERATOR_MACRO_H
 #define _ITERATOR_MACRO_H
 
+#define FWD(x) std::forward<decltype(x)>(x)
+
 #define SFINAE(trait, rval)                                                    \
   template <bool _ = true> std::enable_if_t<trait && _, rval>
 

+ 1 - 0
include/iterator/detail/undef.h

@@ -9,6 +9,7 @@
 #ifdef _ITERATOR_MACRO_H
 #undef _ITERATOR_MACRO_H
 
+#undef FWD
 #undef SFINAE
 #undef EXISTS
 #undef TYPE

+ 0 - 2
include/iterator/forwards.h

@@ -21,8 +21,6 @@ struct sentinel_t;
 
 // Iterator types
 template <typename> class end_aware_iterator;
-template <typename It, typename = typename It::sentinel_type>
-class sentinel_iterator;
 template <typename, typename> class filter_iterator;
 template <typename> class joining_iterator;
 template <typename> class unkeyed_iterator;

+ 1 - 1
include/iterator/join_iterator.h

@@ -47,7 +47,7 @@ public:
   }
 
   template <typename C, typename = std::enable_if_t<detail::is_container_v<C>>>
-  joining_iterator(C && container) : outer_(std::forward<C>(container)) {
+  joining_iterator(C && container) : outer_(FWD(container)) {
     update_iterator();
   }
 

+ 4 - 8
include/iterator/proxy.h

@@ -17,8 +17,7 @@ private:
 public:
   proxy() = default;
   proxy(It impl) : impl_(impl) {}
-  template <typename... Args>
-  proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
+  template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
 
   decltype(auto) dereference() const { return *impl_; }
   void increment() { ++impl_; }
@@ -39,8 +38,7 @@ private:
 public:
   proxy() = default;
   proxy(It impl) : impl_(impl) {}
-  template <typename... Args>
-  proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
+  template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
 
   decltype(auto) dereference() const { return *impl_; }
   void increment() { ++impl_; }
@@ -61,8 +59,7 @@ private:
 public:
   proxy() = default;
   proxy(It impl) : impl_(impl) {}
-  template <typename... Args>
-  proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
+  template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
 
   decltype(auto) dereference() const { return *impl_; }
   void increment() { ++impl_; }
@@ -87,8 +84,7 @@ private:
 public:
   proxy() = default;
   proxy(It impl) : impl_(impl) {}
-  template <typename... Args>
-  proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
+  template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
 
   decltype(auto) dereference() const { return *impl_; }
   void advance(difference_type off) { impl_ += off; }

+ 0 - 32
include/iterator/sentinel_iterator.h

@@ -1,32 +0,0 @@
-//
-//  sentinel_iterator.h
-//  iterator
-//
-//  Created by Sam Jaffe on 3/30/23.
-//  Copyright © 2023 Sam Jaffe. All rights reserved.
-//
-
-#pragma once
-
-#include <iterator/forwards.h>
-#include <iterator/proxy.h>
-
-namespace iterator {
-template <typename It, typename S>
-class sentinel_iterator : public proxy<It, sentinel_iterator<It, S>> {
-public:
-  using super_t = proxy<It, sentinel_iterator<It, S>>;
-  using sentinel_type = sentinel_iterator;
-
-public:
-  using super_t::super_t;
-  sentinel_iterator(S) : super_t() {}
-
-  bool equal_to(sentinel_iterator const & other) const {
-    return (at_end() && other.at_end()) || super_t::impl() == other.impl();
-  }
-  bool at_end() const { return super_t::impl() == S(); }
-};
-}
-
-MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::sentinel_iterator);

+ 0 - 2
iterator.xcodeproj/project.pbxproj

@@ -70,7 +70,6 @@
 		CD5AEB3229D8886200A390A4 /* undef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = undef.h; sourceTree = "<group>"; };
 		CD5AEB3329D8956600A390A4 /* capture_iterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = capture_iterator.h; sourceTree = "<group>"; };
 		CD5AEB3429D897DD00A390A4 /* capture_iterator_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = capture_iterator_test.cxx; sourceTree = "<group>"; };
-		CD6EBE2229D5C93A00F387C1 /* sentinel_iterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sentinel_iterator.h; sourceTree = "<group>"; };
 		CD8D0C7B29D8C0BF00443256 /* default_constructible_function_proxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = default_constructible_function_proxy.h; sourceTree = "<group>"; };
 		CDA2B60928581255004D5353 /* libiterator.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libiterator.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		CDA2B6122858128C004D5353 /* forwards.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = forwards.h; sourceTree = "<group>"; };
@@ -187,7 +186,6 @@
 				CDA2B6142858128C004D5353 /* indexed_iterator.h */,
 				CDA2B61F2858128C004D5353 /* join_iterator.h */,
 				CDA2B6162858128C004D5353 /* recursive_iterator.h */,
-				CD6EBE2229D5C93A00F387C1 /* sentinel_iterator.h */,
 				CDA2B6152858128C004D5353 /* unkeyed_iterator.h */,
 				CDA2B61D2858128C004D5353 /* zip_iterator.h */,
 			);