// // capture.h // iterator // // Created by Sam Jaffe on 9/23/25. // Copyright © 2025 Sam Jaffe. All rights reserved. // #pragma once #include namespace iterator::detail { template class CaptureFn { private: using R = std::invoke_result_t; private: P fn_; void const * key_; mutable R cache_; public: CaptureFn(P fn) : fn_(fn) {} // NOLINT auto const & operator()(T & arg) const { if (key_ != &arg) { new (&cache_) R(std::invoke(fn_, std::forward(arg))); } return cache_; } }; }