Date: Fri, 27 Nov 2026 20:39:36 +0000
On Wed, 25 Nov 2026, 18:57 Александр Поваляев via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> I presume you should use something like "
> template<class CharT,
> class Traits = std::case_insensitive_char_traits<CharT>,
> class Allocator = std::allocator<CharT>>
> class basic_string;". It would be the right design decision.
>
It might be right, or it might not.
Maybe you want to only allow one of "STR" and "str" in the set, but you
want to preserve the original value with the original case, stored as
std::string so that you can retrieve it and use it elsewhere as a
std::string (not as some other specialization of std:: basic_string). Just
because you want to treat it as case insensitive _for the purposes of
lookup in the container_ doesn't mean it is a string that is always case
insensitive. A custom comparison function allows you to decide locally that
case doesn't matter in the container, without having to change the entire
type being stored.
This entire thread seems to be a waste of time. Every time somebody answers
your question or explains something, you dismiss it as irrelevant. You
should try listening to other people and seeing if their point of view has
merit.
> Any other use-case?
>
> ср, 25 нояб. 2026 г. в 20:05, Andre Kostur <andre_at_[hidden]>:
>
>> Let us assume that we're trying to use a
>> "std::unordered_set<std::string>". The strings will be whatever input
>> the user has, but I want the unordered_set to operate on the strings
>> in a case-insensitive manner (and for whatever reason, I don't want to
>> store the canonicalized all-lowercase version of the string). Thus I
>> need a custom comparison function to compare two strings in a
>> case-insensitive manner, and I need a custom hash function so that
>> "Abc" and "aBc" and "abC" all get the same hash values. I'm sure folk
>> could come up with even more exotic cases.
>>
>> On Wed, Nov 25, 2026 at 9:10 AM Александр Поваляев <apovalyaev_at_[hidden]>
>> wrote:
>> >
>> > Use-cases:
>> > (1) when we have to use CompPred instead of comparison operator
>> (operator==);
>> > (2) when there is no comparison operator (operator==) for class Key (it
>> is quite exotic) and bitwise-comparison doesn't make sense for us;
>> >
>> > I think that having two different template arguments (namely, "Hash"
>> and "CompPred") brings an "error-prone flexibility".
>> >
>> > пн, 23 нояб. 2026 г. в 21:23, Andre Kostur <andre_at_[hidden]>:
>> >>
>> >> Use-case of what? Having a (potentially) separate hash and comparison?
>> >>
>> >> On Mon, Nov 23, 2026 at 11:04 AM Александр Поваляев via Std-Proposals
>> >> <std-proposals_at_[hidden]> wrote:
>> >> >
>> >> > I'm just trying to understand the use-case.
>> >> > A straight-forward way is to have a single "hash" function template
>> argument.
>> >> > "operator==" or "CompPred" is only needed for collision resolution
>> policy.
>> >> > The only way to guarantee the same hash function value of any two
>> given keys (k1 and k2), is to have a bitwise comparison of k1 and k2.
>> >> > Anyway, why does it matter how we will find an item inside the
>> bucket, if there is a cure-all such as bitwise comparison.
>> >> >
>> >> > пт, 20 нояб. 2026 г. в 23:50, Arthur O'Dwyer <
>> arthur.j.odwyer_at_[hidden]>:
>> >> >>
>> >> >> On Fri, Nov 20, 2026 at 2:21 PM Александр Поваляев via
>> Std-Proposals <std-proposals_at_[hidden]> 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"),
>> >> >>
>> >> >>
>> >> >> Yes there is.
>> >> >> https://eel.is/c++draft/unord.req#general-5.sentence-2
>> >> >>>
>> >> >>> Two values k1 and k2 are considered equivalent if the container's
>> key equality predicate pred(k1, k2) is valid and returns true when passed
>> those values. If k1 and k2 are equivalent, the container's hash function
>> shall return the same value for both.
>> >> >>
>> >> >>
>> >> >> (Your example code violates that "shall": strings "abc" and "def"
>> are equivalent according to your HashCmp, but your hash<string> does not
>> return the same value for both.)
>> >> >>
>> >> >> HTH,
>> >> >> Arthur
>> >> >
>> >> > --
>> >> > Std-Proposals mailing list
>> >> > Std-Proposals_at_[hidden]
>> >> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
std-proposals_at_[hidden]> wrote:
> I presume you should use something like "
> template<class CharT,
> class Traits = std::case_insensitive_char_traits<CharT>,
> class Allocator = std::allocator<CharT>>
> class basic_string;". It would be the right design decision.
>
It might be right, or it might not.
Maybe you want to only allow one of "STR" and "str" in the set, but you
want to preserve the original value with the original case, stored as
std::string so that you can retrieve it and use it elsewhere as a
std::string (not as some other specialization of std:: basic_string). Just
because you want to treat it as case insensitive _for the purposes of
lookup in the container_ doesn't mean it is a string that is always case
insensitive. A custom comparison function allows you to decide locally that
case doesn't matter in the container, without having to change the entire
type being stored.
This entire thread seems to be a waste of time. Every time somebody answers
your question or explains something, you dismiss it as irrelevant. You
should try listening to other people and seeing if their point of view has
merit.
> Any other use-case?
>
> ср, 25 нояб. 2026 г. в 20:05, Andre Kostur <andre_at_[hidden]>:
>
>> Let us assume that we're trying to use a
>> "std::unordered_set<std::string>". The strings will be whatever input
>> the user has, but I want the unordered_set to operate on the strings
>> in a case-insensitive manner (and for whatever reason, I don't want to
>> store the canonicalized all-lowercase version of the string). Thus I
>> need a custom comparison function to compare two strings in a
>> case-insensitive manner, and I need a custom hash function so that
>> "Abc" and "aBc" and "abC" all get the same hash values. I'm sure folk
>> could come up with even more exotic cases.
>>
>> On Wed, Nov 25, 2026 at 9:10 AM Александр Поваляев <apovalyaev_at_[hidden]>
>> wrote:
>> >
>> > Use-cases:
>> > (1) when we have to use CompPred instead of comparison operator
>> (operator==);
>> > (2) when there is no comparison operator (operator==) for class Key (it
>> is quite exotic) and bitwise-comparison doesn't make sense for us;
>> >
>> > I think that having two different template arguments (namely, "Hash"
>> and "CompPred") brings an "error-prone flexibility".
>> >
>> > пн, 23 нояб. 2026 г. в 21:23, Andre Kostur <andre_at_[hidden]>:
>> >>
>> >> Use-case of what? Having a (potentially) separate hash and comparison?
>> >>
>> >> On Mon, Nov 23, 2026 at 11:04 AM Александр Поваляев via Std-Proposals
>> >> <std-proposals_at_[hidden]> wrote:
>> >> >
>> >> > I'm just trying to understand the use-case.
>> >> > A straight-forward way is to have a single "hash" function template
>> argument.
>> >> > "operator==" or "CompPred" is only needed for collision resolution
>> policy.
>> >> > The only way to guarantee the same hash function value of any two
>> given keys (k1 and k2), is to have a bitwise comparison of k1 and k2.
>> >> > Anyway, why does it matter how we will find an item inside the
>> bucket, if there is a cure-all such as bitwise comparison.
>> >> >
>> >> > пт, 20 нояб. 2026 г. в 23:50, Arthur O'Dwyer <
>> arthur.j.odwyer_at_[hidden]>:
>> >> >>
>> >> >> On Fri, Nov 20, 2026 at 2:21 PM Александр Поваляев via
>> Std-Proposals <std-proposals_at_[hidden]> 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"),
>> >> >>
>> >> >>
>> >> >> Yes there is.
>> >> >> https://eel.is/c++draft/unord.req#general-5.sentence-2
>> >> >>>
>> >> >>> Two values k1 and k2 are considered equivalent if the container's
>> key equality predicate pred(k1, k2) is valid and returns true when passed
>> those values. If k1 and k2 are equivalent, the container's hash function
>> shall return the same value for both.
>> >> >>
>> >> >>
>> >> >> (Your example code violates that "shall": strings "abc" and "def"
>> are equivalent according to your HashCmp, but your hash<string> does not
>> return the same value for both.)
>> >> >>
>> >> >> HTH,
>> >> >> Arthur
>> >> >
>> >> > --
>> >> > Std-Proposals mailing list
>> >> > Std-Proposals_at_[hidden]
>> >> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-11-27 20:39:57
