[MS] Creating a generic insertion iterator, part 2 - devamazonaws.blogspot.com
Last time, we tried to create a generic insertion iterator but ran into trouble because our iterator failed to satisfy the iterator requirements of default constructibility and assignability. We ran into this problem because we stored the lambda as a member of the iterator. So let's not do that! Instead of saving the lambda, we'll just save a pointer to the lambda. template<typename Lambda> struct generic_output_iterator { using iterator_category = std::output_iterator_tag; using value_type = void; using pointer = void; using reference = void; using difference_type = void; generic_output_iterator(Lambda&& lambda) noexcept : insert( std::addressof(lambda) ) {} generic_output_iterator& operator*() noexcept { return *this; } generic_output_iterator& operator++() noexcept { return *this; } generic_output_iterator& operator++(int) noexcept { return *this; } template<typename ...