Questions tagged [equal-range]

25 questions
5
votes
3 answers

How to implement equal range "iterator"

how would one implement generic (aka works for multimap, sorted vector ...) equal range iterator? By this I mean it is an iterator that is a pair of iterators (begin and end of a particular equal_range) Motivation for this is that I have a multimap…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
3
votes
2 answers

Why unordered_map::equal_range upper_bound returns end if a key is less than first map element

I've noticed that unordered_map::equal_range upper_bound (first) returns end if the passed key is less than map's first one #include #include #include using namespace std; int main () { { …
3
votes
2 answers

C++ operations on values given by multiset::equal_range

I'm trying to write a program that is taking 1000 random numbers from 0 to 9 and then counting how many times each number appeared: srand(time(NULL)); multiset M;//multiset that contains 1000 random numbers from 0 to 9 for (int i =…
Ania
  • 450
  • 4
  • 14
3
votes
3 answers

std::equal_range not working with strucutre having operator< defined

I am trying to use std::equal_range with the structure below I have compilation error saying that error: no match for ‘operator<’ . struct MyFoo { int v_; string n_; bool operator<(int v) const { return v_ < v;} }; …
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
3
votes
1 answer

Boost multi_index_container partial index search based on results of partial_index_search

To illustrate my question, I copied below code from the "Phonebook" example of Boost help doc. struct phonebook_entry { std::string family_name; std::string given_name; std::string ssn; std::string phone_number; } And I can do a partial…
Michael
  • 673
  • 2
  • 5
  • 23
2
votes
2 answers

Do we really need two overload for operator () in functor?

Look at this example (from cppreference): #include #include #include struct S { int number; char name; // note: name is ignored by this comparison operator bool operator< ( const S& s ) const {…
Test
  • 564
  • 3
  • 12
2
votes
0 answers

How equal_range is making use of heterogeneous comparison?

How is Comp{} in std::equal_range triggering the Compare operation? Is Comp{} indicating a R-Value being created? #include #include #include struct S { int number; char name; // note: name is…
Test
  • 564
  • 3
  • 12
2
votes
3 answers

Find equal range for container with string with prefix

I am having 2 iterators range_begin,range_end, which are my container. I need to find all string which start with char prefix. Here is my code: template pair FindStartsWith( RandomIt range_begin, RandomIt…
1
vote
1 answer

can i use equal_range to get range of values or end of container?

i know that equal_range(k) gets me range of values: starting with k or element greater than k or end and finishing with element greater than k or end. i wanna modify this behaviour to give me only range of values : starting with k or end finishing…
ahmed allam
  • 377
  • 2
  • 15
1
vote
1 answer

Rcpp: sum multimap values by key using equal range

Below I have a code snippet that encapsulates an issue I am having. What I am trying to do would be trivial in R, but is much more difficult in Rcpp. I am just trying aggregate values according to their respective keys. In this example, I am just…
R_user1233
  • 450
  • 1
  • 4
  • 9
1
vote
0 answers

Erasing an equal_range iterator

I've got a pair of iterators: pair ::iterator, multimap::iterator> range; range = m_DirectoryMap.equal_range(obj); That pair holds duplicated elements in a MultiMap - e.g. there is 1 object that has 2 more…
Calihog
  • 135
  • 2
  • 11
1
vote
3 answers

equal_range and 2 overloads have no legal conversion for 'this' pointer

Here is this simple code #include class MyMap : public std::multimap { public: void foo(const int* bar) const { equal_range(bar); } }; int main() { MyMap myMap; int number; …
OoDeLally
  • 552
  • 1
  • 5
  • 21
1
vote
1 answer

find vs equal_range and performance

I am doing some tests with find, equal_range and my own binary search functions and I am having some trouble understanding why equal_range takes so long when compared with a find. I have a sorted vector and I time the duration of the search…
André Moreira
  • 1,669
  • 4
  • 21
  • 35
0
votes
0 answers

How can I change a visual studio code that creates a thematic map using equal ranges method, into creating thematic map using Natural breaks?

I am trying to use visual studio to create a thematic map that reads the data in my Mapinfo table " Neighborhoods" and show them in a map by dividing the data into equal ranges, and to do that I am using this code: using System; using…
0
votes
1 answer

Using `std::equal_range` with `boost::transform_iterator`

Say I have a struct of Items that I'm storing in an std::set and sorting like so: struct Position { int x; int y; } struct Item { std::string id; Position position; // NOTE: only `position` should matter for equality …
Addy
  • 2,414
  • 1
  • 23
  • 43
1
2