Questions tagged [iterator-range]

11 questions
41
votes
6 answers

How do I iterate equal values with the standard library?

Suppose that I have a vector of something: std::vector v; This vector is sorted, so equal elements are next to each other. What is the best way to get all iterator pairs representing ranges with equal elements (using the standard…
geza
  • 28,403
  • 6
  • 61
  • 135
22
votes
4 answers

Pass a single parameter to a function that expects an iterator range

Consider a function that accepts one or more parameters (e.g. file names). In order to make it versatile, it is advantageous to write it for a general iterator range: template void function(Iter first, Iter last) { // do…
piripiri
  • 1,925
  • 2
  • 18
  • 35
3
votes
1 answer

How do I get iterator into boost fusion map?

I'm trying to get iterator for boost::fusion::map, but I'm missing something. The following works with boost::fusion::vector: typedef vector vector_t; vector_t vec(20,'B',14.5); typedef result_of::begin::type vb; typedef…
stefanB
  • 77,323
  • 27
  • 116
  • 141
3
votes
2 answers

Why do Qt containers like QList and QVector not have iterator range constructors?

The Standard library containers in C++ have constructors that take iterator ranges. This is handy when the content of an input container is convertible to, but not the same as the content in the resulting container, or even if the container is just…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
3
votes
0 answers

C++ range iterator algorithm to collect result

I have written a function to collect the result of a boost iterator range. Here it is: template Output collect(const SinglePassRange & rng) { Output r; boost::range::copy(rng, std::inserter(r,…
Elliot Cameron
  • 5,235
  • 2
  • 27
  • 34
3
votes
1 answer

Best way to return a transform iterator range

Let's say I want to write a simple function keys that takes in a std::map and returns an iterator_range that provides the keys of the map. How would I do it? template Range keys(const std::map & m) { ??? } I want to…
Elliot Cameron
  • 5,235
  • 2
  • 27
  • 34
2
votes
1 answer

boost string_algo return value on find failure

I want to find the first space on a line using boost::string_algo's find first: const boost::iterator_range token_range = boost::find_first(line, " "); I can't seem to find anything in the docs that says what this returns if…
user673679
  • 1,327
  • 1
  • 16
  • 35
2
votes
1 answer

How to return an iterator_range

I would like to create and hold on to an iterator_range. The range is constructed based on a predicate (for this example, I look for even numbers). I can do this, but it seems I must make a copy elements from the underlying vector that is being…
rcohn
  • 23
  • 1
  • 5
1
vote
2 answers

returning boost iterator_range from a member function

I'm trying to create a member function that returns range of an array like below: #include class MyClass { public: boost::iterator_range< double* > range() const{ boost::iterator_range< double* > itr_range…
zontragon
  • 780
  • 1
  • 9
  • 27
1
vote
1 answer

Tokenize string and store result in boost::iterator_range

I need to tokenize (' ','\n','\t' as delimiter) a text with somethink like std::string text = "foo bar"; boost::iterator_range r = some_func_i_dont_know(text); Later I want to get output with: for (auto i: result) …
user1587451
  • 978
  • 3
  • 15
  • 30
0
votes
1 answer

Is there a function for number parsing which works on iterators?

Is there a way in C++ or Boost to parse a number (unsigned long long, if possible) which works directly on wstring iterators? It should be as fast as std::stoull.
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131