|
|
@@ -0,0 +1,42 @@
|
|
|
+//
|
|
|
+// default_constructible_function_proxy.h
|
|
|
+// iterator
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 4/1/23.
|
|
|
+// Copyright © 2023 Sam Jaffe. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#include <optional>include/iterator/detail/default_constructible_function_proxy.h
|
|
|
+
|
|
|
+namespace iterator::detail {
|
|
|
+template <typename F, typename = void>
|
|
|
+class default_constructible_function_proxy {
|
|
|
+public:
|
|
|
+ default_constructible_function_proxy() = default;
|
|
|
+ default_constructible_function_proxy(F func) : func_(func) {}
|
|
|
+
|
|
|
+ template <typename... Args> decltype(auto) operator()(Args &&... args) const {
|
|
|
+ if (!func_) { throw; }
|
|
|
+ return std::invoke(*func_, std::forward<Args>(args)...);
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ std::optional<F> func_;
|
|
|
+};
|
|
|
+
|
|
|
+template <typename F>
|
|
|
+class default_constructible_function_proxy<
|
|
|
+ F, std::enable_if_t<std::is_default_constructible_v<F>>> {
|
|
|
+
|
|
|
+public:
|
|
|
+ default_constructible_function_proxy() = default;
|
|
|
+ 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)...);
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ F func_;
|
|
|
+};
|
|
|
+}
|