| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // 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/macro.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_, FWD(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_, FWD(args)...);
- }
- private:
- F func_;
- };
- }
- #include <iterator/detail/undef.h>
|