Modify

Opened 9 years ago

Closed 7 years ago

#2893 closed Library Submissions (fixed)

Function Input Iterator

Reported by: anonymous Owned by: Dave Abrahams
Milestone: To Be Determined Component: iterator
Version: Severity: Not Applicable
Keywords: iterator function input Cc: mikhailberis@…

Description

Simply put a the function input iterator implementation wraps a nullary function object and allows for bounded iterators using an embedded state variable. The use case is for something like the following:

struct generator {
 typedef int result_type;
 generator() { srand(time(0)); }
 result_type operator() () const { return rand(); }
};

using namespace std;
using namespace boost;

int main(int argc, char * argv[]) {
 generator f;
 copy(
   make_function_input_iterator(f, infinite()),
   make_function_input_iterator(f, infinite()),
   ostream_iterator<int>(cout, " ")
   );
 return 0;
}

And if you don't want an infinite range, you can simply bound it:

copy(
  make_function_input_iterator(f, 0),
  make_function_input_iterator(f, 10),
  ostream_iterator<int>(cout, " ")
);

Attachments (3)

function_input_iterator.hpp (1.9 KB) - added by anonymous 9 years ago.
Implementation header.
function_input_iterator.html (11.9 KB) - added by Dean Michael Berris 9 years ago.
Function iterator documentation (HTML)
function_input_iterator.2.rst (4.3 KB) - added by Dean Michael Berris 9 years ago.
Documentation source (RST)

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by anonymous

Attachment: function_input_iterator.hpp added

Implementation header.

Changed 9 years ago by Dean Michael Berris

Function iterator documentation (HTML)

Changed 9 years ago by Dean Michael Berris

Documentation source (RST)

comment:1 Changed 9 years ago by Dean Michael Berris

Cc: mikhailberis@… added

Was submitting the ticket anonymously earlier (unintentionally). Adding a comment as me (Dean Michael Berris) for proper documentation.

comment:2 Changed 7 years ago by Jeremiah Willcock

Resolution: fixed
Status: newclosed

(In [62615]) Added function_input_iterator from Dean Michael Berris; fixes #2893

comment:3 Changed 7 years ago by Marshall Clow

(In [67792]) Merging fixes to release; fixes #2294 fixes #4918 fixes #3645 refs #2823 refs #1427 refs #2893

comment:4 Changed 7 years ago by mimomorin@…

Resolution: fixed
Status: closedreopened

Reopened until merged into release. ([67792] didn't add function_input_iterator to release.)

comment:5 Changed 7 years ago by Daniel James

Resolution: fixed
Status: reopenedclosed

(In [70709]) Iterator: merge several changes from trunk.

  • Update iterator_facade test for #1019 (header change already merged).
  • Category of each iterator is reduced to a known category before we try to find a minimum. Fixes #1517.
  • function_input_iterator from Dean Michael Berris. Fixes #2893
  • Fix typo in boost/iterator.hpp. Fixes #3434.
  • Always include add_reference header in iterator adaptor header.

Did not merge changes for #1427.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Dave Abrahams.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.