Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #82406

Re: equal_range sucks !

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c++
Subject Re: equal_range sucks !
Date 2021-11-23 17:13 +0100
Organization A noiseless patient Spider
Message-ID <snj401$dk6$1@dont-email.me> (permalink)
References <snivjr$afv$1@dont-email.me> <snivuo$d2n$1@dont-email.me>

Show all headers | View raw


Am 23.11.2021 um 16:04 schrieb Bonita Montero:
> Am 23.11.2021 um 15:59 schrieb Bonita Montero:
>> I just tried this:
>>
>>      pair<cpu_it, cpu_it> foundApicId = equal_range( apicIds.begin(), 
>> apicIds.end(),
>>          apicId, []( cpu_apic_id const &idRange, unsigned apicId ) { 
>> return idRange.apicId == apicId; } );
>>
>> It should be possible that the key for the range has a different type
>> than than the elemnens in the range so that I can compare against a
>> part of the range-objects like in the above code.
>>
>> Instead I'd hat to write:
>>
>>      pair<cpu_it, cpu_it> foundApicId = equal_range( apicIds.begin(), 
>> apicIds.end(),
>>          cpu_apic_id( -1, apicId ), []( cpu_apic_id const &idRange, 
>> cpu_apic_id const &id ) { return idRange.apicId == id.apicId; } );
>>
> 
> And even more: I've to use const-references in my lambda.
> Who thinks up such nonsense ?

I've got it:

equal_range uses sth. lower_bound and upper_bound need < and >
comparison. This could be realized by swapping the parameters
on the predicate, therefore the predicate must be symmetrical.
A solution would be a predicate that returns a strong_ordering
object, so that no swapping would be necessary.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-23 15:59 +0100
  Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-23 16:04 +0100
    Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-23 17:13 +0100
      Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-23 19:53 +0100
        Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-25 15:02 +0100
      Re: equal_range sucks ! Juha Nieminen <nospam@thanks.invalid> - 2021-11-24 08:06 +0000
        Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-24 18:18 +0100
  Re: equal_range sucks ! Marcel Mueller <news.5.maazl@spamgourmet.org> - 2021-11-28 12:36 +0100
    Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-28 17:04 +0100
      Re: equal_range sucks ! Bonita Montero <Bonita.Montero@gmail.com> - 2021-11-28 17:23 +0100

csiph-web