Modify

Ticket #2893 (closed Library Submissions: fixed)

Opened 5 years ago

Last modified 3 years ago

Function Input Iterator

Reported by: anonymous Owned by: dave
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

function_input_iterator.hpp Download (1.9 KB) - added by anonymous 5 years ago.
Implementation header.
function_input_iterator.html Download (11.9 KB) - added by mikhailberis 5 years ago.
Function iterator documentation (HTML)
function_input_iterator.2.rst Download (4.3 KB) - added by mikhailberis 5 years ago.
Documentation source (RST)

Change History

Changed 5 years ago by anonymous

Implementation header.

Changed 5 years ago by mikhailberis

Function iterator documentation (HTML)

Changed 5 years ago by mikhailberis

Documentation source (RST)

comment:1 Changed 5 years ago by mikhailberis

  • Cc mikhailberis@… added

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

comment:2 Changed 4 years ago by jewillco

  • Status changed from new to closed
  • Resolution set to fixed

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

comment:3 Changed 3 years ago by marshall

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

comment:4 Changed 3 years ago by mimomorin@…

  • Status changed from closed to reopened
  • Resolution fixed deleted

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

comment:5 Changed 3 years ago by danieljames

  • Status changed from reopened to closed
  • Resolution set to fixed

(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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.