Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Using TSO is like kicking a dead whale down the beach. -- S. C. Johnson


devel / comp.lang.c++ / Re: What a bug

SubjectAuthor
* What a bugBonita Montero
+* Re: What a bugAlf P. Steinbach
|+- Re: What a bugChris M. Thomasson
|`* Re: What a bugBonita Montero
| `* Re: What a bugMuttley
|  `* Re: What a bugBonita Montero
|   +* Re: What a bugBonita Montero
|   |`- Re: What a bugBonita Montero
|   `* Re: What a bugMuttley
|    `- Re: What a bugBonita Montero
+* Re: What a bugChris M. Thomasson
|`* Re: What a bugBonita Montero
| +* Re: What a bugChris M. Thomasson
| |+* Re: What a bugBonita Montero
| ||`* Re: What a bugChris M. Thomasson
| || +* Re: What a bugBonita Montero
| || |`- Re: What a bugBonita Montero
| || `* Re: What a bugChris M. Thomasson
| ||  `- Re: What a bugChris M. Thomasson
| |`* Re: What a bugScott Lurndal
| | `- Re: What a bugChris M. Thomasson
| `* Re: What a bugPavel
|  +- Re: What a bugred floyd
|  `* Re: What a bugBonita Montero
|   `* Re: What a bugPavel
|    `* Re: What a bugBonita Montero
|     `* Re: What a bugPavel
|      `* Re: What a bugBonita Montero
|       `* Re: What a bugPavel
|        `* Re: What a bugBonita Montero
|         `* Re: What a bugPavel
|          +* Re: What a bugBonita Montero
|          |`* Re: What a bugBonita Montero
|          | `- Re: What a bugPavel
|          `- Re: What a bugBonita Montero
`* Re: What a bugjak
 `* Re: What a bugjak
  +* Re: What a bugKeith Thompson
  |+* Re: What a bugjak
  ||+- Re: What a bugBonita Montero
  ||`* Re: What a bugKeith Thompson
  || `* Re: What a bugjak
  ||  `- Re: What a bugJames Kuyper
  |`- Re: What a bugBonita Montero
  `* Re: What a bugred floyd
   +* Re: What a bugKeith Thompson
   |`- Re: What a bugred floyd
   `- Re: What a bugBonita Montero

Pages:12
Re: What a bug

<ud6qom$1tniq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1321&group=comp.lang.c%2B%2B#1321

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@please.ty (jak)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 5 Sep 2023 11:01:09 +0200
Organization: A noiseless patient Spider
Lines: 118
Message-ID: <ud6qom$1tniq$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <87pm2y6af4.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 5 Sep 2023 09:01:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1eb422b28a3179c475f2c83d0b7a4617";
logging-data="2023002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JOkKJ/Ex3fWG19zASITUi"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
Cancel-Lock: sha1:chY330a92qwbUXnzrpprvxE9V2M=
In-Reply-To: <87pm2y6af4.fsf@nosuchdomain.example.com>
 by: jak - Tue, 5 Sep 2023 09:01 UTC

Keith Thompson ha scritto:
> jak <nospam@please.ty> writes:
>> jak ha scritto:
>>> Bonita Montero ha scritto:
>>>> I checked for some commandline options and I thought it would be the
>>>> best to map that through an unordered_map. I extracted this from my
>>>> application in the below code.
>>>>
>>>> #include <Windows.h>
>>>> #include <iostream>
>>>> #include <variant>
>>>> #include <unordered_map>
>>>>
>>>> using namespace std;
>>>>
>>>> int wmain( int argc, wchar_t **argv )
>>>> {
>>>>      static unordered_map<wchar_t const *, DWORD>
>>>>          const opts =
>>>>      {
>>>>          { L"--idle", IDLE_PRIORITY_CLASS },
>>>>          { L"--below", BELOW_NORMAL_PRIORITY_CLASS },
>>>>          { L"--above", ABOVE_NORMAL_PRIORITY_CLASS },
>>>>          { L"--high", HIGH_PRIORITY_CLASS },
>>>>          { L"--realtime", REALTIME_PRIORITY_CLASS }
>>>>      };
>>>>      auto mappedPrio = opts.find( "--high" );
>>>>      if( mappedPrio == opts.end() )
>>>>          return -1;
>>>>      return 0;
>>>> }
>>>>
>>>> Why does my code have a bug and why doesn't mappedPrio
>>>> point to end() at the end?
>>> HI,
>>> you just need to use wchar_t in your search string as well:
>>> from:
>>> auto mappedPrio = opts.find( "--high" );
>>> to:
>>> auto mappedPrio = opts.find( L"--high" );
>>>
>>
>> mmm. This only works because the compiler uses the same area of memory
>> as the strings are equal and therefore compares a pointer to itself when
>> it finds the string. In fact if I replace this:
>>
>> auto mappedPrio = opts.find( L"--high" );
>>
>> with this other:
>>
>> wchar_t what[] = L"--high";
>> auto mappedPrio = opts.find( what );
>>
>> the search fails.
>>
>> I find this sneaky. In my opinion the compiler shouldn't treat two
>> objects as the same just because they have the same content.
>
> The find() function of unordered_map<> compares keys for *equality*.
>
> Since the code defines the key type as `wchar_t const *`, it does
> pointer comparison, which has all the usual problems when you apply it
> to string literals; L"foo" and L"foo" may or may not be stored at the
> same memory location, and L"foo" and a string L"foo" derived from user
> input will certainly not have the same address.
>
> You can specify an equality function if you like.
>
> A far simpler solution is to use std::wstring as the key type.
>

HI,
I probably expressed myself badly. I agree with what you answered and
everything is clear to me. What I am contesting is the part where you
say "...may or may not be stored at the same memory location" because
that would mean that a program like this:

#include <iostream>

int main()
{ auto eif = [] (bool t) {
std::cout << ( t ? "equal" : "not equal" ) << std::endl;
};

char const *sp = "hello";
char sl[] = "hello";

eif( sp == sp );

eif( "hello" == sp );

eif( "hello" == "hello" );

eif( "hello" == sl );

return 0;
}

which has this as a result:

equal
equal
equal
not equal

could give different results depending on how the compiler acts when
deciding where to store strings (because here we are comparing
pointers). I simply think that different objects shouldn't be lumped
together just because they contain the same things, otherwise I would
have declared a single string and would have used its pointer around the
code. Pointers are for that too. it is my opinion that the program I
posted should have this as a result:

equal
not equal
not equal
not equal

Re: What a bug

<ud6rcg$1tq9a$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1322&group=comp.lang.c%2B%2B#1322

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 5 Sep 2023 11:11:44 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <ud6rcg$1tq9a$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <87pm2y6af4.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 5 Sep 2023 09:11:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e3dcd7ff00e37181b9b9938002eec9d6";
logging-data="2025770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bkmkDZ2ZMm6XrTrda2jGjJCyh0HhP1U0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5YiXqcXkog18gfaUG8vRc9UHt+4=
In-Reply-To: <87pm2y6af4.fsf@nosuchdomain.example.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 5 Sep 2023 09:11 UTC

Am 04.09.2023 um 02:37 schrieb Keith Thompson:

> A far simpler solution is to use std::wstring as the key type.

A string_view is much more perfromant and allows to reference
external strings - if applicable.

Re: What a bug

<ud6rep$1tq9a$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1323&group=comp.lang.c%2B%2B#1323

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 5 Sep 2023 11:12:57 +0200
Organization: A noiseless patient Spider
Lines: 123
Message-ID: <ud6rep$1tq9a$2@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <87pm2y6af4.fsf@nosuchdomain.example.com>
<ud6qom$1tniq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 5 Sep 2023 09:12:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e3dcd7ff00e37181b9b9938002eec9d6";
logging-data="2025770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199qD/dCi1FjeWIS4wyYezalYgYxYM725I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:t8ff+uhEeCF7fMFmnlkZkE0GC6w=
Content-Language: de-DE
In-Reply-To: <ud6qom$1tniq$1@dont-email.me>
 by: Bonita Montero - Tue, 5 Sep 2023 09:12 UTC

Am 05.09.2023 um 11:01 schrieb jak:
> Keith Thompson ha scritto:
>> jak <nospam@please.ty> writes:
>>> jak ha scritto:
>>>> Bonita Montero ha scritto:
>>>>> I checked for some commandline options and I thought it would be the
>>>>> best to map that through an unordered_map. I extracted this from my
>>>>> application in the below code.
>>>>>
>>>>> #include <Windows.h>
>>>>> #include <iostream>
>>>>> #include <variant>
>>>>> #include <unordered_map>
>>>>>
>>>>> using namespace std;
>>>>>
>>>>> int wmain( int argc, wchar_t **argv )
>>>>> {
>>>>>       static unordered_map<wchar_t const *, DWORD>
>>>>>           const opts =
>>>>>       {
>>>>>           { L"--idle", IDLE_PRIORITY_CLASS },
>>>>>           { L"--below", BELOW_NORMAL_PRIORITY_CLASS },
>>>>>           { L"--above", ABOVE_NORMAL_PRIORITY_CLASS },
>>>>>           { L"--high", HIGH_PRIORITY_CLASS },
>>>>>           { L"--realtime", REALTIME_PRIORITY_CLASS }
>>>>>       };
>>>>>       auto mappedPrio = opts.find( "--high" );
>>>>>       if( mappedPrio == opts.end() )
>>>>>           return -1;
>>>>>       return 0;
>>>>> }
>>>>>
>>>>> Why does my code have a bug and why doesn't mappedPrio
>>>>> point to end() at the end?
>>>> HI,
>>>> you just need to use wchar_t in your search string as well:
>>>> from:
>>>> auto mappedPrio = opts.find( "--high" );
>>>> to:
>>>> auto mappedPrio = opts.find( L"--high" );
>>>>
>>>
>>> mmm. This only works because the compiler uses the same area of memory
>>> as the strings are equal and therefore compares a pointer to itself when
>>> it finds the string. In fact if I replace this:
>>>
>>> auto mappedPrio = opts.find( L"--high" );
>>>
>>> with this other:
>>>
>>> wchar_t what[] =  L"--high";
>>> auto mappedPrio = opts.find( what );
>>>
>>> the search fails.
>>>
>>> I find this sneaky. In my opinion the compiler shouldn't treat two
>>> objects as the same just because they have the same content.
>>
>> The find() function of unordered_map<> compares keys for *equality*.
>>
>> Since the code defines the key type as `wchar_t const *`, it does
>> pointer comparison, which has all the usual problems when you apply it
>> to string literals; L"foo" and L"foo" may or may not be stored at the
>> same memory location, and L"foo" and a string L"foo" derived from user
>> input will certainly not have the same address.
>>
>> You can specify an equality function if you like.
>>
>> A far simpler solution is to use std::wstring as the key type.
>>
>
> HI,
> I probably expressed myself badly. I agree with what you answered and
> everything is clear to me. What I am contesting is the part where you
> say "...may or may not be stored at the same memory location" because
> that would mean that a program like this:
>
> #include <iostream>
>
> int main()
> {
>     auto eif = [] (bool t) {
>         std::cout << ( t ? "equal" : "not equal" ) << std::endl;
>     };
>
>     char const *sp = "hello";
>     char sl[] = "hello";

Try to make s1 static const, then it may be joined.

>
>     eif( sp == sp );
>
>     eif( "hello" == sp );
>
>     eif( "hello" == "hello" );
>
>     eif( "hello" == sl );
>
>     return 0;
> }
>
> which has this as a result:
>
> equal
> equal
> equal
> not equal
>
> could give different results depending on how the compiler acts when
> deciding where to store strings (because here we are comparing
> pointers). I simply think that different objects shouldn't be lumped
> together just because they contain the same things, otherwise I would
> have declared a single string and would have used its pointer around the
> code. Pointers are for that too. it is my opinion that the program I
> posted should have this as a result:
>
> equal
> not equal
> not equal
> not equal

Re: What a bug

<87v8cp3phf.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1324&group=comp.lang.c%2B%2B#1324

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 05 Sep 2023 03:04:44 -0700
Organization: None to speak of
Lines: 88
Message-ID: <87v8cp3phf.fsf@nosuchdomain.example.com>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me>
<87pm2y6af4.fsf@nosuchdomain.example.com>
<ud6qom$1tniq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="d633fa9147221aa5a66d8a19b6f926fe";
logging-data="2040859"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bMa9tAZPBm7NtqmVkXEzF"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:WeasPzFMx/iuNnbOwPi0xnO5poU=
sha1:zZccEZo5WchUjJtnQk+/gzc+GGE=
 by: Keith Thompson - Tue, 5 Sep 2023 10:04 UTC

jak <nospam@please.ty> writes:
[...]
> I probably expressed myself badly. I agree with what you answered and
> everything is clear to me. What I am contesting is the part where you
> say "...may or may not be stored at the same memory location" because
> that would mean that a program like this:
>
> #include <iostream>
>
> int main()
> {
> auto eif = [] (bool t) {
> std::cout << ( t ? "equal" : "not equal" ) << std::endl;
> };
>
> char const *sp = "hello";
> char sl[] = "hello";
>
> eif( sp == sp );
>
> eif( "hello" == sp );
>
> eif( "hello" == "hello" );
>
> eif( "hello" == sl );
>
> return 0;
> }
>
> which has this as a result:
>
> equal
> equal
> equal
> not equal
>
> could give different results depending on how the compiler acts when
> deciding where to store strings (because here we are comparing
> pointers).

Yes, that's exactly what it means.

> I simply think that different objects shouldn't be lumped
> together just because they contain the same things, otherwise I would
> have declared a single string and would have used its pointer around the
> code. Pointers are for that too. it is my opinion that the program I
> posted should have this as a result:
>
> equal
> not equal
> not equal
> not equal

I suggest the language standard is more relevant than either of our
opinions.

C++17 5.13.5 [lex.string] paragraph 16:

Evaluating a *string-literal* results in a string literal
object with static storage duration, initialized from the given
characters as specified above. Whether all string literals are
distinct (that is, are stored in nonoverlapping objects) and
whether successive evaluations of a *string-literal* yield the
same or a different object is unspecified. [ Note: The effect
of attempting to modify a string literal is undefined. — end
note ]

I believe that all versions of C and C++ have similar rules.

Which means that ("hello" == "hello") may be either true or false, and
an implementation is not required to document which.

In your program above, this:
sp == sp
is guaranteed to be true, these:
"hello" == sp
"hello" == "hello"
may be either true or false, and this:
"hello" == sl
is false because sl is distinct and explicitly defined array object.

If you compile your program with clang++, it prints warnings on all four
comparisons.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: What a bug

<ud8t48$2bm7e$1@redfloyd.dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1325&group=comp.lang.c%2B%2B#1325

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail
From: no.spam.here@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 5 Sep 2023 20:53:44 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ud8t48$2bm7e$1@redfloyd.dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Sep 2023 03:53:45 -0000 (UTC)
Injection-Info: redfloyd.dont-email.me; posting-host="f01aa774057f3d965846286cc491465e";
logging-data="2480366"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/udpemA3aV0tA8zQ31ZfouuemfVwgvmeo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:CKSTevzv7RiQMv+2Do7iM9vIzOc=
In-Reply-To: <ud2t4q$12vk6$1@dont-email.me>
Content-Language: en-US
 by: red floyd - Wed, 6 Sep 2023 03:53 UTC

On 9/3/2023 2:17 PM, jak wrote:

>> you just need to use wchar_t in your search string as well:
>>
>> from:
>> auto mappedPrio = opts.find( "--high" );
>> to:
>> auto mappedPrio = opts.find( L"--high" );
>>
>>
>
> mmm. This only works because the compiler uses the same area of memory
> as the strings are equal and therefore compares a pointer to itself when
> it finds the string. In fact if I replace this:
>

No, I believe that std::unordered_map has a specialization for both
const char* and const wchar_t*.

Re: What a bug

<8734zs3pky.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1326&group=comp.lang.c%2B%2B#1326

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 05 Sep 2023 21:14:53 -0700
Organization: None to speak of
Lines: 23
Message-ID: <8734zs3pky.fsf@nosuchdomain.example.com>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <ud8t48$2bm7e$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f546b0f93539422d57b55f18c37467f2";
logging-data="2484453"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dH4aBph3ryO1Hnlwdhbgj"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:4n2EzcvancvfXYym7xuU2A0ZUWY=
sha1:NQkAo5lHJvavpN9tUejGo55jobg=
 by: Keith Thompson - Wed, 6 Sep 2023 04:14 UTC

red floyd <no.spam.here@its.invalid> writes:
> On 9/3/2023 2:17 PM, jak wrote:
>>> you just need to use wchar_t in your search string as well:
>>>
>>> from:
>>> auto mappedPrio = opts.find( "--high" );
>>> to:
>>> auto mappedPrio = opts.find( L"--high" );
>>>
>> mmm. This only works because the compiler uses the same area of
>> memory
>> as the strings are equal and therefore compares a pointer to itself when
>> it finds the string. In fact if I replace this:
>
> No, I believe that std::unordered_map has a specialization for both
> const char* and const wchar_t*.

I don't believe that's correct. Do you have a reference?

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: What a bug

<ud90c3$2c52i$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1327&group=comp.lang.c%2B%2B#1327

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Wed, 6 Sep 2023 06:49:09 +0200
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <ud90c3$2c52i$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <ud8t48$2bm7e$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Sep 2023 04:49:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e0f7816222c6bdb3f46074addb6b82cd";
logging-data="2495570"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18begMAap6wUqZ7KYNd4s3hhl76/ty8LPA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dfKK2Cbe8OPDaJRiqVBcZUYnhIs=
In-Reply-To: <ud8t48$2bm7e$1@redfloyd.dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 6 Sep 2023 04:49 UTC

Am 06.09.2023 um 05:53 schrieb red floyd:

> No, I believe that std::unordered_map has a specialization
> for both const char* and const wchar_t*.

Would be nice but actually this isn't true.

Re: What a bug

<rm1KM.1058416$TPw2.302579@fx17.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1328&group=comp.lang.c%2B%2B#1328

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
Subject: Re: What a bug
Newsgroups: comp.lang.c++
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <ud68h1$1r8t7$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 13
Message-ID: <rm1KM.1058416$TPw2.302579@fx17.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Wed, 06 Sep 2023 16:00:23 UTC
Date: Wed, 6 Sep 2023 12:00:06 -0400
X-Received-Bytes: 1298
 by: Pavel - Wed, 6 Sep 2023 16:00 UTC

Bonita Montero wrote:
> Am 05.09.2023 um 00:43 schrieb Pavel:
>
>> If you cared about the speed, why did you use unordered_map?
>
> My original example wasn't about speed. And the map is static, so it's
> initialized thread-safe on the first run. But if I store strings in the
> map, a string object is created with every lookup with a string literal,
It does not have to be created since C++ 20.

> which may result in a memory allocation. Depending on the case, this may
> be too slow.

Re: What a bug

<udadtj$2jf1f$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1329&group=comp.lang.c%2B%2B#1329

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Wed, 6 Sep 2023 19:46:29 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <udadtj$2jf1f$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Sep 2023 17:46:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e0f7816222c6bdb3f46074addb6b82cd";
logging-data="2735151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TbwJRmkgDC3a8/BkbOp2QP829u1RA5fM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:7j2yZkO6r2WxrWWEck/F+uGs0hs=
Content-Language: de-DE
In-Reply-To: <rm1KM.1058416$TPw2.302579@fx17.iad>
 by: Bonita Montero - Wed, 6 Sep 2023 17:46 UTC

Am 06.09.2023 um 18:00 schrieb Pavel:

> Bonita Montero wrote:

>> My original example wasn't about speed. And the map is static, so it's
>> initialized thread-safe on the first run. But if I store strings in the
>> map, a string object is created with every lookup with a string literal,

> It does not have to be created since C++ 20.

The string-object is created for every lookup with a string-literal
if the key is also a string-object. That has nothing to do with C++20.
The thread-safe initialization of the map, which is usually done with
double-checked locking, is guaranteed since C++11.

Re: What a bug

<FM3KM.1257010$GMN3.837996@fx16.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1331&group=comp.lang.c%2B%2B#1331

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
Subject: Re: What a bug
Newsgroups: comp.lang.c++
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udadtj$2jf1f$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 30
Message-ID: <FM3KM.1257010$GMN3.837996@fx16.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Wed, 06 Sep 2023 18:44:53 UTC
Date: Wed, 6 Sep 2023 14:44:45 -0400
X-Received-Bytes: 1955
 by: Pavel - Wed, 6 Sep 2023 18:44 UTC

Bonita Montero wrote:
> Am 06.09.2023 um 18:00 schrieb Pavel:
>
>> Bonita Montero wrote:
>
>>> My original example wasn't about speed. And the map is static, so it's
>>> initialized thread-safe on the first run. But if I store strings in the
>>> map, a string object is created with every lookup with a string literal,
>
>> It does not have to be created since C++ 20.
>
> The string-object is created for every lookup with a string-literal
> if the key is also a string-object.
False. Read the standard.

> That has nothing to do with C++20.
False. Read the standard, e.g. how to use

template<class Key,
class T,
class Hash = hash<Key>,
class Pred = equal_to<Key>,
class Allocator = allocator<pair<const Key, T>>>
class unordered_map {
template<class K> iterator find(const K& k);
template<class K> const_iterator find(const K& k) const;
};

> The thread-safe initialization of the map, which is usually done with
> double-checked locking, is guaranteed since C++11.

Re: What a bug

<udb1c2$2mc8a$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1336&group=comp.lang.c%2B%2B#1336

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@please.ty (jak)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 01:18:25 +0200
Organization: A noiseless patient Spider
Lines: 126
Message-ID: <udb1c2$2mc8a$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <87pm2y6af4.fsf@nosuchdomain.example.com>
<ud6qom$1tniq$1@dont-email.me> <87v8cp3phf.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 6 Sep 2023 23:18:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="685bf23fa1b307c4eb9051fb4618a919";
logging-data="2830602"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6HqLnqO5KBgIK4niMJfoc"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
Cancel-Lock: sha1:xArEZa9e2gz7Z6FGmA6QcfOxdy8=
In-Reply-To: <87v8cp3phf.fsf@nosuchdomain.example.com>
 by: jak - Wed, 6 Sep 2023 23:18 UTC

Keith Thompson ha scritto:
> jak <nospam@please.ty> writes:
> [...]
>> I probably expressed myself badly. I agree with what you answered and
>> everything is clear to me. What I am contesting is the part where you
>> say "...may or may not be stored at the same memory location" because
>> that would mean that a program like this:
>>
>> #include <iostream>
>>
>> int main()
>> {
>> auto eif = [] (bool t) {
>> std::cout << ( t ? "equal" : "not equal" ) << std::endl;
>> };
>>
>> char const *sp = "hello";
>> char sl[] = "hello";
>>
>> eif( sp == sp );
>>
>> eif( "hello" == sp );
>>
>> eif( "hello" == "hello" );
>>
>> eif( "hello" == sl );
>>
>> return 0;
>> }
>>
>> which has this as a result:
>>
>> equal
>> equal
>> equal
>> not equal
>>
>> could give different results depending on how the compiler acts when
>> deciding where to store strings (because here we are comparing
>> pointers).
>
> Yes, that's exactly what it means.
>
>> I simply think that different objects shouldn't be lumped
>> together just because they contain the same things, otherwise I would
>> have declared a single string and would have used its pointer around the
>> code. Pointers are for that too. it is my opinion that the program I
>> posted should have this as a result:
>>
>> equal
>> not equal
>> not equal
>> not equal
>
> I suggest the language standard is more relevant than either of our
> opinions.
>
> C++17 5.13.5 [lex.string] paragraph 16:
>
> Evaluating a *string-literal* results in a string literal
> object with static storage duration, initialized from the given
> characters as specified above. Whether all string literals are
> distinct (that is, are stored in nonoverlapping objects) and
> whether successive evaluations of a *string-literal* yield the
> same or a different object is unspecified. [ Note: The effect
> of attempting to modify a string literal is undefined. — end
> note ]
>
> I believe that all versions of C and C++ have similar rules.
>
> Which means that ("hello" == "hello") may be either true or false, and
> an implementation is not required to document which.
>
> In your program above, this:
> sp == sp
> is guaranteed to be true, these:
> "hello" == sp
> "hello" == "hello"
> may be either true or false, and this:
> "hello" == sl
> is false because sl is distinct and explicitly defined array object.
>
> If you compile your program with clang++, it prints warnings on all four
> comparisons.
>
Thanks for sending the paragraph. Unfortunately I had only sought it
just before your post.
However, it is obvious that it prints the warnings, I extracted the test
intentionally from the function/method, because otherwise the compiler
does not recognize the UB. If I modified my program in this way:

$ cat ./pp.cpp
#include <iostream>

int main()
{ auto eif = [] (char const *a, char const *b) {
std::cout << ( ( a == b ) ? "equal" : "not equal" ) << std::endl;
};
char const *sp = "hello";
char sl[] = "hello";

eif( sp, sp );
eif( "hello", sp );
eif( "hello", "hello" );
eif( "hello", sl );

return 0;
}

$ g++ -Wall -Wpedantic -Werror -std=c++17 ./pp.cpp -o ./pp

$ ./pp
equal
equal
equal
not equal

$ _

The warnings disappear but the UB remain. For this reason I think that
making objects unique because they have the same content is a bad
practice. Furthermore, the fact that it may happen or not makes the fact
even worse.

Re: What a bug

<udb6ra$2n1cb$1@redfloyd.dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1337&group=comp.lang.c%2B%2B#1337

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail
From: no.spam.here@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Wed, 6 Sep 2023 17:51:54 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <udb6ra$2n1cb$1@redfloyd.dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <ud8t48$2bm7e$1@redfloyd.dont-email.me>
<8734zs3pky.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 00:51:54 -0000 (UTC)
Injection-Info: redfloyd.dont-email.me; posting-host="6f49a88cb947fadb759352dd5bbcd562";
logging-data="2852235"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19U8bfk4y6KEdKvOvU1atETNp7ZLMZyVLk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:B0aa9/pcmV1TbkrL+0Kdo0j+6/s=
Content-Language: en-US
In-Reply-To: <8734zs3pky.fsf@nosuchdomain.example.com>
 by: red floyd - Thu, 7 Sep 2023 00:51 UTC

On 9/5/2023 9:14 PM, Keith Thompson wrote:
> red floyd <no.spam.here@its.invalid> writes:
>> On 9/3/2023 2:17 PM, jak wrote:
>>>> you just need to use wchar_t in your search string as well:
>>>>
>>>> from:
>>>> auto mappedPrio = opts.find( "--high" );
>>>> to:
>>>> auto mappedPrio = opts.find( L"--high" );
>>>>
>>> mmm. This only works because the compiler uses the same area of
>>> memory
>>> as the strings are equal and therefore compares a pointer to itself when
>>> it finds the string. In fact if I replace this:
>>
>> No, I believe that std::unordered_map has a specialization for both
>> const char* and const wchar_t*.
>
> I don't believe that's correct. Do you have a reference?
>

Isn't it based on std::less<>?

Just checked. My mistake, forget I said anything.

Re: What a bug

<udbdr2$2rk0p$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1338&group=comp.lang.c%2B%2B#1338

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 04:51:15 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <udbdr2$2rk0p$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 02:51:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="707347a35c765578889e4f3b790e82e5";
logging-data="3002393"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18k00n2KPCQYO+Y+oEZr9eUwuDo5b/476c="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:pWxsNeZFdwolANf2bZage28OhH4=
In-Reply-To: <FM3KM.1257010$GMN3.837996@fx16.iad>
Content-Language: de-DE
 by: Bonita Montero - Thu, 7 Sep 2023 02:51 UTC

Am 06.09.2023 um 20:44 schrieb Pavel:

> Bonita Montero wrote:

>> The string-object is created for every lookup with a string-literal
>> if the key is also a string-object.

> False. Read the standard.

Quote the standard.

>> That has nothing to do with C++20.

> False. Read the standard, e.g. how to use

Quote the standard.

> template<class Key,
> class T,
> class Hash = hash<Key>,
> class Pred = equal_to<Key>,
> class Allocator = allocator<pair<const Key, T>>>
> class unordered_map {
> template<class K> iterator find(const K& k);
> template<class K> const_iterator find(const K& k) const;
> };

Theres a templated K-parameter for the loookup, but internally
this parameter needs to be converted to a string-object to be
hashed and to be equality-comparable the same way.
In theory there might be overloaded specializations that take
a string_view or whatever; but that's ratther unlikely.

Re: What a bug

<2QbKM.543979$Fgta.410052@fx10.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1340&group=comp.lang.c%2B%2B#1340

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
Subject: Re: What a bug
Newsgroups: comp.lang.c++
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udbdr2$2rk0p$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 39
Message-ID: <2QbKM.543979$Fgta.410052@fx10.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 07 Sep 2023 03:54:38 UTC
Date: Wed, 6 Sep 2023 23:54:38 -0400
X-Received-Bytes: 2101
 by: Pavel - Thu, 7 Sep 2023 03:54 UTC

Bonita Montero wrote:
> Am 06.09.2023 um 20:44 schrieb Pavel:
>
>> Bonita Montero wrote:
>
>>> The string-object is created for every lookup with a string-literal
>>> if the key is also a string-object.
>
>> False. Read the standard.
>
> Quote the standard.
>
>>> That has nothing to do with C++20.
>
>> False. Read the standard, e.g. how to use
>
> Quote the standard.
>
>> template<class Key,
>> class T,
>> class Hash = hash<Key>,
>> class Pred = equal_to<Key>,
>> class Allocator = allocator<pair<const Key, T>>>
>> class unordered_map {
>> template<class K> iterator find(const K& k);
>> template<class K> const_iterator find(const K& k) const;
>> };
>
> Theres a templated K-parameter for the loookup, but internally
> this parameter needs to be converted to a string-object to be
> hashed and to be equality-comparable the same way.
correct

> In theory there might be overloaded specializations that take
> a string_view or whatever;
not needed

> but that's ratther unlikely.
close but imprecise. That's simply not there.

Re: What a bug

<udbla5$2sds6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1343&group=comp.lang.c%2B%2B#1343

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 06:58:47 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <udbla5$2sds6$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 04:58:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="707347a35c765578889e4f3b790e82e5";
logging-data="3028870"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZSps49+q9SNit02kHwVKmRajmuw7JcY8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2O8XbwxfWCxRAPJvW5P7Cby12f0=
Content-Language: de-DE
In-Reply-To: <2QbKM.543979$Fgta.410052@fx10.iad>
 by: Bonita Montero - Thu, 7 Sep 2023 04:58 UTC

Am 07.09.2023 um 05:54 schrieb Pavel:

>> In theory there might be overloaded specializations that take
>> a string_view or whatever;

> not needed

With out such a specialization a string object needs to be created
inside find to have compatible hashing and equality comparison.

>> but that's ratther unlikely.

> close but imprecise. That's simply not there.

That's a theoretically valid possibility,
so it can't be said that it doesn't exist.

Re: What a bug

<qHlKM.1326052$GMN3.523782@fx16.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1351&group=comp.lang.c%2B%2B#1351

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
Subject: Re: What a bug
Newsgroups: comp.lang.c++
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
<udbla5$2sds6$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udbla5$2sds6$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 158
Message-ID: <qHlKM.1326052$GMN3.523782@fx16.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 07 Sep 2023 15:08:06 UTC
Date: Thu, 7 Sep 2023 11:08:05 -0400
X-Received-Bytes: 5627
 by: Pavel - Thu, 7 Sep 2023 15:08 UTC

Bonita Montero wrote:
> Am 07.09.2023 um 05:54 schrieb Pavel:
>
>>> In theory there might be overloaded specializations that take
>>> a string_view or whatever;
>
>> not needed
>
> With out such a specialization a string object needs to be created
> inside find to have compatible hashing and equality comparison.

Not true. I was benevolently trying to make you read the standard so you
could become a better C++ programmer but you refused.

I am therefore giving up on helping you. I will become evil and post the
complete standard-compliant example that demonstrates how exactly the
unordered_map::find can be made work on string literal and the map with
the string keys without creating a string object (in the example, the
string is wrapped in StringKey to track constructions easily but you are
welcome to remove the wrapper). The code will work as described under
C++20 but not any previous version of the standard -- and this is the
expected behavior.

You still have a chance to improve your C++ programming skills if you
read the standard and find the explanation for why this code shall
behave like it does.

// ------------- code begin cut here -------------------------
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>

using namespace std;

class StringKey {like
public:
StringKey(const char* cStr): s_(cStr) {
cout << "\n\t(StringKey(" << cStr << ") called)\n";
}
const string& getS() const { return s_; }
private:
string s_;
};

struct StringKeyHash {
typedef void is_transparent;
size_t operator()(const char *s) const {
assert(!!s);
return Hash(s, s + strlen(s));
}
size_t operator()(const StringKey &s) const {
return Hash(s.getS().data(), s.getS().data() + s.getS().size());
}
private:
static size_t Hash(const char* begin, const char* end) {
return accumulate(begin, end, (size_t) 0u,
[](size_t a, char c) -> size_t { return a + (size_t)c; });
}
};

struct StringKeyEq {
typedef void is_transparent;
bool operator()(const StringKey& x, const StringKey& y) const {
return IsEq(x.getS().c_str(), y.getS().c_str());
}
bool operator()(const StringKey& x, const char* y) const {
assert(!!y);
return IsEq(x.getS().c_str(), y);
}
bool operator()(const char* x, const StringKey& y) const {
assert(!!x);
return IsEq(x, y.getS().c_str());
}
private:
static bool IsEq(const char *x, const char *y) {
assert(!!x);
assert(!!y);
for (;; ++x, ++y) {
if (*x == *y) {
if (!*x)
return true;
continue;
}
assert(*x != *y);
return false;
}
}
};

int
main(int, char*[]) {
cout << "*** fill up the unordered map\n";
unordered_map<StringKey, string, StringKeyHash, StringKeyEq> um {
{ "key1", "val1" },
{ "key2", "val2" },
};
const char* key3 = "key3";
const char* key4 = "key4";
const char* key1 = "key1";
cout << "*** now do the the find\n";
const auto i1 = um.find(key1);
const bool r1 = i1 == um.end();
const auto i3 = um.find(key3);
const bool r3 = i3 == um.end();
const auto i4 = um.find(key4);
const bool r4 = i4 == um.end();
cout << "find(" << key1 << "):" << r1 << ' ' <<
"find(" << key4 << "):" << r4 << ' ' <<
"find(" << key3 << "):" << r3 << endl;

return 0;
}

// ------------- code end cut here -------------------------

// --- example run output if compiled by g++ -std=c++20 begin ---
$ ./a.out
*** fill up the unordered map

(StringKey(key1) called)

(StringKey(key2) called)
*** now do the the find
find(key1):0 find(key4):1 find(key3):1
// --- example run output if compiled by g++ -std=c++20 end ---

// --- example run output if compiled by g++ -std=c++17 begin ---
$ ./a.out
*** fill up the unordered map

(StringKey(key1) called)

(StringKey(key2) called)
*** now do the the find

(StringKey(key1) called)

(StringKey(key3) called)

(StringKey(key4) called)
find(key1):0 find(key4):1 find(key3):1
// --- example run output if compiled by g++ -std=c++17 end ---

>
>>> but that's ratther unlikely.
>
>> close but imprecise. That's simply not there.
>
> That's a theoretically valid possibility,
> so it can't be said that it doesn't exist.
This is "theoretically valid" only for those who refuse to read the
standard; the others know the specialization is not there.

Re: What a bug

<udcrqf$31mqp$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1353&group=comp.lang.c%2B%2B#1353

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 17:56:01 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <udcrqf$31mqp$3@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
<udbla5$2sds6$1@dont-email.me> <qHlKM.1326052$GMN3.523782@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 15:55:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="707347a35c765578889e4f3b790e82e5";
logging-data="3201881"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18D2dmJ80F2uZx3BAr8oqlnkC3If1y3XVA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nKPEUWaQxlds7yP4zzF81w52xew=
In-Reply-To: <qHlKM.1326052$GMN3.523782@fx16.iad>
Content-Language: de-DE
 by: Bonita Montero - Thu, 7 Sep 2023 15:56 UTC

Am 07.09.2023 um 17:08 schrieb Pavel:

> Not true. I was benevolently trying to make you read the standard
> so you could become a better C++ programmer but you refused.

You're making a total differnt discussion and don't notce where's my
point. Within find for a string key a string key is generated from K
if the key is a string-object; that's all. What's wrong with that ?
The alternative you're showing below is sth. completely different
and the idea came across my mind when I discovered what's the problem
with my bug. But a string_view could much more performant if you won't
do any additional allocations per inserted node.
But that's not my point. Should I disable just my code debugging with
MSVC and show you the code which converts a string-pointer to a com-
pararable string-object ?

Rest unread.
Idiot !

Re: What a bug

<udcsaj$31mqp$4@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1354&group=comp.lang.c%2B%2B#1354

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 18:04:37 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <udcsaj$31mqp$4@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
<udbla5$2sds6$1@dont-email.me> <qHlKM.1326052$GMN3.523782@fx16.iad>
<udcrqf$31mqp$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 16:04:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="707347a35c765578889e4f3b790e82e5";
logging-data="3201881"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GWwub/ZNuQK8sanxiJUaf7+0XIrt54Z8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jXs7wZxeU4fwAvZBlk8lvIjrPTc=
In-Reply-To: <udcrqf$31mqp$3@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 7 Sep 2023 16:04 UTC

Am 07.09.2023 um 17:56 schrieb Bonita Montero:

> You're making a total differnt discussion and don't notce where's my
> point. Within find for a string key a string key is generated from K
> if the key is a string-object; that's all. What's wrong with that ?

Here are the declarations for C++20 from en.cppreference.com:

template< class K >
iterator find( const K& x );
(3) (since C++20)
template< class K >
const_iterator find( const K& x ) const;
(4) (since C++20)

MSVC hasn't code for that even I use C++20. I think MS dropped
that because an internal conversion within find() could be also
done externally while calling find(). Smart decision.

Re: What a bug

<x7tKM.758940$qnnb.72202@fx11.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1368&group=comp.lang.c%2B%2B#1368

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
Subject: Re: What a bug
Newsgroups: comp.lang.c++
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
<udbla5$2sds6$1@dont-email.me> <qHlKM.1326052$GMN3.523782@fx16.iad>
<udcrqf$31mqp$3@dont-email.me> <udcsaj$31mqp$4@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udcsaj$31mqp$4@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 32
Message-ID: <x7tKM.758940$qnnb.72202@fx11.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 07 Sep 2023 23:35:57 UTC
Date: Thu, 7 Sep 2023 19:35:48 -0400
X-Received-Bytes: 2535
 by: Pavel - Thu, 7 Sep 2023 23:35 UTC

Bonita Montero wrote:
> Am 07.09.2023 um 17:56 schrieb Bonita Montero:
>
>> You're making a total differnt discussion and don't notce where's my
>> point. Within find for a string key
what is a "find for a string key"? Earlier you referred to a "lookup
with a string-literal" which is what this discussion is about.

> a string key is generated from K
>> if the key is a string-object; that's all. What's wrong with that ?
>
> Here are the declarations for C++20 from en.cppreference.com:
>
> template< class K >
> iterator find( const K& x );
>     (3)     (since C++20)
> template< class K >
> const_iterator find( const K& x ) const;
>     (4)     (since C++20)
>
> MSVC hasn't code for that even I use C++20. I think MS dropped
> that because an internal conversion within find()
What "internal conversion" within find() do you refer to? What is the
source type? What is the destination type?

> could be also
> done externally while calling find(). Smart decision.
No, just a defect. Not including the template version of find() is
non-compliant with C++20 because it is affects for C++ programs. As a
simple example, it makes a valid C++20 program fail to compile if that
program calls one of unordered_map::find templates with the explicitly
specified template parameter type.

Re: What a bug

<udcr9g$31mqp$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1370&group=comp.lang.c%2B%2B#1370

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 7 Sep 2023 17:46:58 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <udcr9g$31mqp$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <U4tJM.421219$Fgta.289098@fx10.iad>
<ud68h1$1r8t7$1@dont-email.me> <rm1KM.1058416$TPw2.302579@fx17.iad>
<udadtj$2jf1f$1@dont-email.me> <FM3KM.1257010$GMN3.837996@fx16.iad>
<udbdr2$2rk0p$1@dont-email.me> <2QbKM.543979$Fgta.410052@fx10.iad>
<udbla5$2sds6$1@dont-email.me> <qHlKM.1326052$GMN3.523782@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Sep 2023 15:46:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="707347a35c765578889e4f3b790e82e5";
logging-data="3201881"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rAaLV8uydKhwcx8ZJW27RC2dehz5HqHo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fzOIt9/SmFBOwcAUNgjkkxjKorw=
Content-Language: de-DE
In-Reply-To: <qHlKM.1326052$GMN3.523782@fx16.iad>
 by: Bonita Montero - Thu, 7 Sep 2023 15:46 UTC

Am 07.09.2023 um 17:08 schrieb Pavel:

> Not true. I was benevolently trying to make you read the standard
> so you could become a better C++ programmer but you refused.

You're making a total differnt discussion and don't notce where's my
point. Within find for a string key a string key is generated from K
if the key is a string-object; that's all. What's wrong with that ?
The alternative you're showing below is sth. completely different
and the idea came across my mind when I discovered what's the problem
with my bug. But a string_view could much more performant if you won't
do any additional allocations per inserted node.
But that's not my point. Should I disable just my code debugging with
MSVC and show you the code which converts a string-pointer to a com-
pararable string-object ?

Rest unread.
Idiot !

Re: What a bug

<ude6pm$3av40$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1371&group=comp.lang.c%2B%2B#1371

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Fri, 8 Sep 2023 00:09:26 -0400
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ude6pm$3av40$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
<ud2t4q$12vk6$1@dont-email.me> <87pm2y6af4.fsf@nosuchdomain.example.com>
<ud6qom$1tniq$1@dont-email.me> <87v8cp3phf.fsf@nosuchdomain.example.com>
<udb1c2$2mc8a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 04:09:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d850d9259a9c21eaa026960b2033421d";
logging-data="3505280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19V1O65+e2ixzJjDzDJikUuMh/x/Y7kwjI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:qOhn8R/PkfpOCPBhNN5/PUIXp1E=
Content-Language: en-US
In-Reply-To: <udb1c2$2mc8a$1@dont-email.me>
 by: James Kuyper - Fri, 8 Sep 2023 04:09 UTC

On 9/6/23 19:18, jak wrote:
....
> However, it is obvious that it prints the warnings, I extracted the test
> intentionally from the function/method, because otherwise the compiler
> does not recognize the UB. If I modified my program in this way:
>
> $ cat ./pp.cpp
> #include <iostream>
>
> int main()
> {
> auto eif = [] (char const *a, char const *b) {
> std::cout << ( ( a == b ) ? "equal" : "not equal" ) << std::endl;
> };
> char const *sp = "hello";
> char sl[] = "hello";
>
> eif( sp, sp );
> eif( "hello", sp );
> eif( "hello", "hello" );
> eif( "hello", sl );
>
> return 0;
> }
>
> $ g++ -Wall -Wpedantic -Werror -std=c++17 ./pp.cpp -o ./pp
>
> $ ./pp
> equal
> equal
> equal
> not equal
>
> $ _
>
> The warnings disappear but the UB remain.

What UB are you referring to?

Re: What a bug

<ue04tm$2svjh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1483&group=comp.lang.c%2B%2B#1483

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Thu, 14 Sep 2023 16:27:49 -0700
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ue04tm$2svjh$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <ud3154$13irg$2@dont-email.me>
<ud3gqo$19fto$1@dont-email.me> <ud3hag$19h7u$1@dont-email.me>
<ud61e7$1qed6$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Sep 2023 23:27:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d3282d606c828846e96819dd9df0e37e";
logging-data="3047025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cSEnSluou9NFuZbrRTnnmM8dNVbARVYY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:DruQIx/C90UO99+D9RpzqnmZWyE=
In-Reply-To: <ud61e7$1qed6$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 14 Sep 2023 23:27 UTC

On 9/4/2023 6:48 PM, Chris M. Thomasson wrote:
> On 9/3/2023 8:01 PM, Chris M. Thomasson wrote:
>> On 9/3/2023 7:53 PM, Bonita Montero wrote:
>>> Am 04.09.2023 um 00:25 schrieb Chris M. Thomasson:
>>>
>>>> Right. Afaict, there is a way to create the strings on the stack and
>>>> use a little adapter logic to make it work with std::unordered_map.
>>>> So, no dynamic allocation.
>>>
>>> You can simply have a string_view as suggested in this thread.
>>>
>>
>> A view into strings stored on the stack.
>
> Check this out, my little experiment with stacks, used in a per-thread
> allocator:
>
> https://pastebin.com/raw/f37a23918
>

> https://groups.google.com/g/comp.lang.c/c/7oaJFWKVCTw/m/sSWYU9BUS_QJ
^^^^^^^^^^^

Wow, way back in 2009. How time flies!

Re: What a bug

<uealvc$206ck$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1584&group=comp.lang.c%2B%2B#1584

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 18 Sep 2023 16:20:12 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <uealvc$206ck$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me> <ud3154$13irg$2@dont-email.me>
<VMlJM.780913$mPI2.515002@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 18 Sep 2023 23:20:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2103700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sVKfntJbCFLQi0qEJJcYGkIrnxYeUOxc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:XAsH+ZDIx+Tv53xPOUqDm5NCNf4=
Content-Language: en-US
In-Reply-To: <VMlJM.780913$mPI2.515002@fx15.iad>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 23:20 UTC

On 9/4/2023 7:24 AM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 9/1/2023 9:19 PM, Bonita Montero wrote:
>>> Am 01.09.2023 um 23:50 schrieb Chris M. Thomasson:
>>>
>>>> Try something like:
>>>
>>> I know that I could have done that easier, but I wanted to know
>>> where's the bug and why my example does find the key value anyway.
>>>
>>>> ___________________________
>>>> #include <iostream>
>>>> #include <unordered_map>
>>>> #include <string>
>>>> #include <cstdlib>
>>>>
>>>>
>>>> int main()
>>>> {
>>>>      static std::unordered_map<std::string, long> opts = {
>>>>        {"--idle", 0 },
>>>>        {"--below", 1 },
>>>>        {"--above", 2 },
>>>>        {"--high", 3 },
>>>>        {"--realtime", 4 }
>>>>      };
>>>>
>>>>      auto mapped_opt = opts.find("--realtime");
>>>
>>> The problem here is that each find creates a string-object,
>>> which is rather slow.
>>
>> Right. Afaict, there is a way to create the strings on the stack and use
>> a little adapter logic to make it work with std::unordered_map. So, no
>> dynamic allocation.
>
> Or just use getopt_long() with UTF-8 strings.

:^)

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor