From 523c7c7e388ac71c62ce28f41e663f83857e1e54 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 1 Aug 2017 13:31:47 +1000 Subject: [PATCH] iterator: add the OutputIterator "discard_iterator" --- iterator.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/iterator.hpp b/iterator.hpp index c5bbde62..892ef45c 100644 --- a/iterator.hpp +++ b/iterator.hpp @@ -279,6 +279,22 @@ namespace util { data... ); } -} + + + /////////////////////////////////////////////////////////////////////////// + /// an output iterator that always discards any parameters on assignment. + /// + /// sometimes useful to pass to algorithms that generate useful results as + /// a return value, while not caring about the implicit OutputIterator + /// results. + struct discard_iterator : public std::iterator { + template + void operator= (const T&) { ; } + + discard_iterator& operator++ ( ) { return *this; } + discard_iterator operator++ (int) { return *this; } + discard_iterator& operator* ( ) { return *this; } + }; +}; #endif