Opened 14 years ago

Closed 12 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 14 years ago.
Implementation header.
function_input_iterator.html (11.9 KB ) - added by Dean Michael Berris 14 years ago.
Function iterator documentation (HTML)
function_input_iterator.2.rst (4.3 KB ) - added by Dean Michael Berris 14 years ago.
Documentation source (RST)

Download all attachments as: .zip

Change History (8)

by anonymous, 14 years ago

Attachment: function_input_iterator.hpp added

Implementation header.

by Dean Michael Berris, 14 years ago

Function iterator documentation (HTML)

by Dean Michael Berris, 14 years ago

Documentation source (RST)

comment:1 by Dean Michael Berris, 14 years ago

Cc: mikhailberis@… added

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

comment:2 by Jeremiah Willcock, 12 years ago

Resolution: fixed
Status: newclosed

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

comment:3 by Marshall Clow, 12 years ago

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

comment:4 by mimomorin@…, 12 years ago

Resolution: fixed
Status: closedreopened

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

comment:5 by Daniel James, 12 years ago

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.

Note: See TracTickets for help on using tickets.