Date: Sat, 21 Nov 2026 10:42:54 +0300
I am using laptop MacOS 10.15.8 (Catalina)
"g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
--with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin"
пт, 20 нояб. 2026 г. в 23:03, <paul_at_[hidden]>:
> As we all know .count() returns the number of items that compare equal
> to what is given so it should be 1. For it to be zero likely means the
> internal code doesn't see any equal elements (which is incorrect). What
> platform/compiler/standard library (and versions) did you use?
>
> ASIDE: On my computer with GCC and Clang I get "1 1 1".
>
> Paul
>
>
> On 2026-11-20 14:21, Александр Поваляев via Std-Proposals wrote:
> > Colleagues, good morning!
> >
> > unordered_set container allos "hash" and "compare" functions
> > specifications through template arguments. Something like this
> > "unordered_set<string, hash<string>, HashCmp> a;". On the other hand
> > there is neither invariant specified (in cppreference or any other
> > relevant web resources) for these two functions ("hash" and
> > "compare"), nor any runtime or compile time assert-like functionality
> > to support consistent logic.
> > Why is this necessary (invariant or check)?
> > Because in practice we can face out a stupid, but still real-life
> > scenarios, when all these associative staff would malfunction.
> > Here is an example:
> >
> > #include <unordered_set>
> >
> > #include <string>
> >
> > #include <iostream>
> >
> > using namespace std;
> >
> > struct HashCmp {
> >
> > bool operator ()(const string& left, const string& right) const {
> >
> > return left.size() == right.size();
> >
> > }
> >
> > };
> >
> > int main() {
> >
> > unordered_set<string, hash<string>, HashCmp> a;
> >
> > a.emplace("AAAA");
> >
> > a.emplace("BBBB");
> >
> > a.emplace("CCCC");
> >
> > cout << a.count("AAAA") << " " << a.count("BBBB") << " " <<
> > a.count("CCCC") << endl;
> >
> > }
> >
> > Do you think it will output "1 1 1"?
> >
> > On my laptop this scenario shows "1 1 0".
> >
> > Regards,
> >
> > Alex
>
"g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr
--with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin"
пт, 20 нояб. 2026 г. в 23:03, <paul_at_[hidden]>:
> As we all know .count() returns the number of items that compare equal
> to what is given so it should be 1. For it to be zero likely means the
> internal code doesn't see any equal elements (which is incorrect). What
> platform/compiler/standard library (and versions) did you use?
>
> ASIDE: On my computer with GCC and Clang I get "1 1 1".
>
> Paul
>
>
> On 2026-11-20 14:21, Александр Поваляев via Std-Proposals wrote:
> > Colleagues, good morning!
> >
> > unordered_set container allos "hash" and "compare" functions
> > specifications through template arguments. Something like this
> > "unordered_set<string, hash<string>, HashCmp> a;". On the other hand
> > there is neither invariant specified (in cppreference or any other
> > relevant web resources) for these two functions ("hash" and
> > "compare"), nor any runtime or compile time assert-like functionality
> > to support consistent logic.
> > Why is this necessary (invariant or check)?
> > Because in practice we can face out a stupid, but still real-life
> > scenarios, when all these associative staff would malfunction.
> > Here is an example:
> >
> > #include <unordered_set>
> >
> > #include <string>
> >
> > #include <iostream>
> >
> > using namespace std;
> >
> > struct HashCmp {
> >
> > bool operator ()(const string& left, const string& right) const {
> >
> > return left.size() == right.size();
> >
> > }
> >
> > };
> >
> > int main() {
> >
> > unordered_set<string, hash<string>, HashCmp> a;
> >
> > a.emplace("AAAA");
> >
> > a.emplace("BBBB");
> >
> > a.emplace("CCCC");
> >
> > cout << a.count("AAAA") << " " << a.count("BBBB") << " " <<
> > a.count("CCCC") << endl;
> >
> > }
> >
> > Do you think it will output "1 1 1"?
> >
> > On my laptop this scenario shows "1 1 0".
> >
> > Regards,
> >
> > Alex
>
Received on 2026-11-21 07:43:08
