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; } );
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 ?
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.
lower_bound and upper_bound need < and > comparison.
Bonita Montero <Bonita.Montero@gmail.com> wrote:
lower_bound and upper_bound need < and > comparison.
I'm pretty certain they only require that the elements are comparable
with std::less() (which means that operator<() is enough).
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.
Am 23.11.21 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.
Feel free to write an asymmetric comparer that fits your needs.
You may also implement an asymmetric operator<, but implicitly comparing apples with oranges is not a good advice.
template<typename RandomIt, typename T, typename Pred>
std::pair<RandomIt, RandomIt> xequal_range( RandomIt begin, RandomIt
end, T const &key, Pred pred )
requires std::random_access_iterator<RandomIt>
&&
requires( Pred pred, typename std::iterator_traits<RandomIt>::value_type &elem, T const &key )
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 185 |
Nodes: | 16 (1 / 15) |
Uptime: | 21:02:21 |
Calls: | 3,730 |
Calls today: | 13 |
Files: | 11,159 |
D/L today: |
2 files (4,496K bytes) |
Messages: | 3,452,900 |