Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Feeling amorous, she looked under the sheets and cried, "Oh, no, it's Microsoft!"


devel / comp.lang.c++ / 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
What a bug

<uct7ch$3uope$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: What a bug
Date: Fri, 1 Sep 2023 19:35:14 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <uct7ch$3uope$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Sep 2023 17:35:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e8a6437ed2f33ea5f9c07e973e035ef9";
logging-data="4154158"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GZv8UKn8rJzt+oaWeovfOi/zKPtpAhaI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:itZ1lyKjaC/dB7zOzf8SzdC+sUM=
Content-Language: de-DE
 by: Bonita Montero - Fri, 1 Sep 2023 17:35 UTC

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?

Re: What a bug

<uctjtv$r76$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: alf.p.st...@gmail.com (Alf P. Steinbach)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Fri, 1 Sep 2023 23:09:19 +0200
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <uctjtv$r76$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Sep 2023 21:09:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f728c60168bde018a49de898dfd50cbb";
logging-data="27878"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XQbcd7YQVXwjK5yhb2D0B"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Oiy0aF3VI7eY0n+cGIfSd6KNUqc=
Content-Language: en-US
In-Reply-To: <uct7ch$3uope$1@dont-email.me>
 by: Alf P. Steinbach - Fri, 1 Sep 2023 21:09 UTC

On 2023-09-01 7:35 PM, Bonita Montero wrote:
> 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?

How did you get that to compile?

With the compilation-spoiler fixed and the `-1` replaced with either
`E_FAIL` or `EXIT_FAILURE` (for the latter include `<stdlib.h>`), the
problem you're /probably/ talking about is why it doesn't work with your
setup to compare pointers to string literals. That's because the Holy
Standard does not require string pooling. An easy fix is to use
`wstring_view` as key (for that include `<string_view>`).

- Alf

Re: What a bug

<uctmag$1a28$1@dont-email.me>

  copy mid

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

  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....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Fri, 1 Sep 2023 14:50:08 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uctmag$1a28$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Sep 2023 21:50:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="772ecddaa31e7496b60fd951c691d463";
logging-data="43080"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hYoaeGkIiCqsm4IULPDP8Oot0I7lkUWo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:eD6iejfVWqc87lfaqBLMV9YCk6s=
Content-Language: en-US
In-Reply-To: <uct7ch$3uope$1@dont-email.me>
 by: Chris M. Thomasson - Fri, 1 Sep 2023 21:50 UTC

On 9/1/2023 10:35 AM, Bonita Montero wrote:
> 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?

Try something like:
___________________________
#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");

if(mapped_opt == opts.end())
{
std::cout << "ahhh, shit!!!" << std::endl;

return EXIT_FAILURE;
}

std::cout << mapped_opt->first << ", " << mapped_opt->second <<
std::endl;

return EXIT_SUCCESS;
} ___________________________

?

Re: What a bug

<uctmf0$1a97$1@dont-email.me>

  copy mid

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

  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....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Fri, 1 Sep 2023 14:52:32 -0700
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uctmf0$1a97$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Sep 2023 21:52:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="772ecddaa31e7496b60fd951c691d463";
logging-data="43303"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NzQsAowRuSxq82nR6UwGk4IBRkjwqh90="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:nXNCnoKqdZeojSAG/r92WxMbOGU=
In-Reply-To: <uctjtv$r76$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 1 Sep 2023 21:52 UTC

On 9/1/2023 2:09 PM, Alf P. Steinbach wrote:
> On 2023-09-01 7:35 PM, Bonita Montero wrote:
>> 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?
>
> How did you get that to compile?
>
> With the compilation-spoiler fixed and the `-1` replaced with either
> `E_FAIL` or `EXIT_FAILURE` (for the latter include `<stdlib.h>`), the
> problem you're /probably/ talking about is why it doesn't work with your
> setup to compare pointers to string literals.

Yup.

> That's because the Holy
> Standard does not require string pooling. An easy fix is to use
> `wstring_view` as key (for that include `<string_view>`).
>
> - Alf

Re: What a bug

<ucud4u$a111$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 06:19:43 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <ucud4u$a111$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 2 Sep 2023 04:19:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="328737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+z2/oCUr5Z7X4TpG7lRvOkISJKG0yr4No="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zz+i9EBXGBkoDE9ieTEwuYZVZCM=
In-Reply-To: <uctmag$1a28$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 2 Sep 2023 04:19 UTC

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.

Re: What a bug

<ucudb5$a111$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 06:23:02 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <ucudb5$a111$2@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Sep 2023 04:23:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="328737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vPyFBCSt/OO24qfSjZ6wmBhPooCuWSJY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2wUW7hO/gb7cOS4wxuQN1eIanws=
In-Reply-To: <uctjtv$r76$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 2 Sep 2023 04:23 UTC

Am 01.09.2023 um 23:09 schrieb Alf P. Steinbach:

> the problem you're /probably/ talking about is why it doesn't work with your
> setup to compare pointers to string literals. That's because the Holy
> Standard does not require string pooling. An easy fix is to use
> `wstring_view` as key (for that include `<string_view>`).

Exactly, that's what I did afterwards. But I first thought
that my code works because the linker has joined my both
"--high" strings to the same address.

Re: What a bug

<ucv2if$co8d$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 10:25:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <ucv2if$co8d$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me> <ucudb5$a111$2@dont-email.me>
Injection-Date: Sat, 2 Sep 2023 10:25:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="918a1a5d491e8c7082cade476118fd75";
logging-data="418061"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ygge4LITDRC9aL0vCaedY"
Cancel-Lock: sha1:WFj/ZZxTnvPfr382pkbMOx9Drqg=
 by: Mutt...@dastardlyhq.com - Sat, 2 Sep 2023 10:25 UTC

On Sat, 2 Sep 2023 06:23:02 +0200
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 01.09.2023 um 23:09 schrieb Alf P. Steinbach:
>
>> the problem you're /probably/ talking about is why it doesn't work with
>your
>> setup to compare pointers to string literals. That's because the Holy
>> Standard does not require string pooling. An easy fix is to use
>> `wstring_view` as key (for that include `<string_view>`).
>
>Exactly, that's what I did afterwards. But I first thought
>that my code works because the linker has joined my both
>"--high" strings to the same address.

There's nothing in the standard saying that should be the case. I thought
you were a C++ god?

Re: What a bug

<ucv4dp$cutc$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 12:56:58 +0200
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <ucv4dp$cutc$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
<ucudb5$a111$2@dont-email.me> <ucv2if$co8d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Sep 2023 10:56:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="424876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+taS6tWTur2shegWyHGptYQp7sBnMtkxY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:z3/SPo+JKUYznGnd3gcKKIx+Bf8=
Content-Language: de-DE
In-Reply-To: <ucv2if$co8d$1@dont-email.me>
 by: Bonita Montero - Sat, 2 Sep 2023 10:56 UTC

Am 02.09.2023 um 12:25 schrieb Muttley@dastardlyhq.com:

> On Sat, 2 Sep 2023 06:23:02 +0200
> Bonita Montero <Bonita.Montero@gmail.com> wrote:

>> Exactly, that's what I did afterwards. But I first thought
>> that my code works because the linker has joined my both
>> "--high" strings to the same address.

> There's nothing in the standard saying that should be the case.

No, but also nothing that forbids that.
And actually the linkers do that.

Try this at home:

#include <iostream>

int main()
{ std::cout << ("xxx" == "xxx") << std::endl;
}

Although MSVC joined the strings in my first example it doesnt
do that in this example. Bug g++ and clang++ do join the strings.

> I thought you were a C++ god?

Sounds you are not.

Re: What a bug

<ucva79$dq4l$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 14:35:54 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <ucva79$dq4l$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
<ucudb5$a111$2@dont-email.me> <ucv2if$co8d$1@dont-email.me>
<ucv4dp$cutc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 2 Sep 2023 12:35:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="452757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UCCSV8g73er5xiP4FM6DZ6gqaObNxM0g="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:gNsSTMb4pOm07Wtd9H9u9ZsKd2U=
In-Reply-To: <ucv4dp$cutc$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 2 Sep 2023 12:35 UTC

Am 02.09.2023 um 12:56 schrieb Bonita Montero:

> No, but also nothing that forbids that.
> And actually the linkers do that.
>
> Try this at home:
>
> #include <iostream>
>
> int main()
> {
>     std::cout << ("xxx" == "xxx") << std::endl;
> }

I found a small imcompatibility between MSVC's cl and "MSVC's" clang-cl:

C:\Users\Boni>cl -Ox -MD join.cpp -EHs
....
C:\Users\Boni>join
0 C:\Users\Boni>clang-cl -Ox -MD join.cpp -EHs
....
C:\Users\Boni>join
1

Maybe someone relies on the uniqueness or on the joining.

Re: What a bug

<ucvahn$drqk$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 14:41:28 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ucvahn$drqk$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
<ucudb5$a111$2@dont-email.me> <ucv2if$co8d$1@dont-email.me>
<ucv4dp$cutc$1@dont-email.me> <ucva79$dq4l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Sep 2023 12:41:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="454484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iDpDoLLt6si3Dm64eV8jkATbVEIghiu4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IoOfYCDWz429yFEvCI6V0/ztyPU=
Content-Language: de-DE
In-Reply-To: <ucva79$dq4l$1@dont-email.me>
 by: Bonita Montero - Sat, 2 Sep 2023 12:41 UTC

Am 02.09.2023 um 14:35 schrieb Bonita Montero:

> I found a small imcompatibility between MSVC's cl and "MSVC's" clang-cl:
>
> C:\Users\Boni>cl -Ox -MD join.cpp -EHs
> ...
> C:\Users\Boni>join
> 0
> C:\Users\Boni>clang-cl -Ox -MD join.cpp -EHs
> ...
> C:\Users\Boni>join
> 1
>
> Maybe someone relies on the uniqueness or on the joining.

I found that there is a commandline-option of MSVC and clang-cl that
directs the compiler to join strings with -GF or not with -GF-. For
MSVC the default is not to join the strings, for clang-cl the default
is to join the strings.

Re: What a bug

<ucvkes$f7sb$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 15:30:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <ucvkes$f7sb$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
<ucudb5$a111$2@dont-email.me> <ucv2if$co8d$1@dont-email.me>
<ucv4dp$cutc$1@dont-email.me>
Injection-Date: Sat, 2 Sep 2023 15:30:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="918a1a5d491e8c7082cade476118fd75";
logging-data="499595"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tCtFzad6+W7zlWASXob3q"
Cancel-Lock: sha1:wR3Ys4RrG2tm/3UP/QtOgQIp7jM=
 by: Mutt...@dastardlyhq.com - Sat, 2 Sep 2023 15:30 UTC

On Sat, 2 Sep 2023 12:56:58 +0200
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 02.09.2023 um 12:25 schrieb Muttley@dastardlyhq.com:
>
>> On Sat, 2 Sep 2023 06:23:02 +0200
>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>
>>> Exactly, that's what I did afterwards. But I first thought
>>> that my code works because the linker has joined my both
>>> "--high" strings to the same address.
>
>> There's nothing in the standard saying that should be the case.
>
>No, but also nothing that forbids that.

There's nothing forbidding a lot of things but relying on them always being
the case would lead to some interesting bugs when the code is compiled on
a compiler that uses a different approach.

Re: What a bug

<ucvmph$fgo5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 18:10:26 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ucvmph$fgo5$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctjtv$r76$1@dont-email.me>
<ucudb5$a111$2@dont-email.me> <ucv2if$co8d$1@dont-email.me>
<ucv4dp$cutc$1@dont-email.me> <ucvkes$f7sb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Sep 2023 16:10:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6d7baca48fbf7bc02becbc3dd1670c4e";
logging-data="508677"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JU+M5OdAj2dJYzaDy4eta1uWWeOicOyY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rV25RigbcZx9kr81oQv5HO1NSIo=
Content-Language: de-DE
In-Reply-To: <ucvkes$f7sb$1@dont-email.me>
 by: Bonita Montero - Sat, 2 Sep 2023 16:10 UTC

Am 02.09.2023 um 17:30 schrieb Muttley@dastardlyhq.com:

> There's nothing forbidding a lot of things but relying on them always being
> the case would lead to some interesting bugs when the code is compiled on
> a compiler that uses a different approach.

I just wanted to verify what I did wrong with my unordered map, having
a wchar_t-pointer as the key, and accidentally MSVC joined the strings
and the key actually was found because the keys shared the addresses.
So I this was all accidentally and I didn't rely on anything.
But if you're stuck with MS cl or clang-cl and you use the -GF(-) switch
correctly - as I said both have different defaults - you could even rely
on that anyway if you're writing a Windows application.

Re: What a bug

<ud08l2$i4aq$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sat, 2 Sep 2023 23:15:13 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <ud08l2$i4aq$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 2 Sep 2023 21:15:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c720dfa91832adeb2dfc16208c370e6a";
logging-data="594266"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18u5dimASegTYha6FMeuKNz"
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:ohaQW83dZ7FbzwyN3LD5BCu/Hjs=
In-Reply-To: <uct7ch$3uope$1@dont-email.me>
 by: jak - Sat, 2 Sep 2023 21:15 UTC

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" );

Re: What a bug

<ud2t4q$12vk6$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nos...@please.ty (jak)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sun, 3 Sep 2023 23:17:13 +0200
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <ud2t4q$12vk6$1@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <ud08l2$i4aq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Sep 2023 21:17:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="95653a43cf47d6971bc52b7905a302ff";
logging-data="1146502"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193llijB4klM0y/cuSjioWU"
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:kw6gEomTnNHGHcQUIzNWeIEr2D4=
In-Reply-To: <ud08l2$i4aq$1@dont-email.me>
 by: jak - Sun, 3 Sep 2023 21:17 UTC

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.

Re: What a bug

<ud3154$13irg$2@dont-email.me>

  copy mid

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

  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....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sun, 3 Sep 2023 15:25:41 -0700
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <ud3154$13irg$2@dont-email.me>
References: <uct7ch$3uope$1@dont-email.me> <uctmag$1a28$1@dont-email.me>
<ucud4u$a111$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Sep 2023 22:25:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbfec9bf80a1760bb972bf83cd8a0103";
logging-data="1166192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XCHv7yaaBeN5GpI3lwVrXygjqhREVg3Y="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:pLd7iIouICja1oic+jT2W5o81Us=
In-Reply-To: <ucud4u$a111$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 3 Sep 2023 22:25 UTC

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.

Re: What a bug

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

  copy mid

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

  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....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sun, 03 Sep 2023 17:37:19 -0700
Organization: None to speak of
Lines: 73
Message-ID: <87pm2y6af4.fsf@nosuchdomain.example.com>
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
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="2d5fff03b065922503ffa3043f03177b";
logging-data="1195771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gnheifAMF0t0Lr8SjbToM"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:U21Cy0ZoVR4JCI2tzLLPzclRGew=
sha1:7HxA75avs1jhAMDYWC3LcEgCpT0=
 by: Keith Thompson - Mon, 4 Sep 2023 00:37 UTC

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.

--
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

<ud3gqo$19fto$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 4 Sep 2023 04:53:14 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <ud3gqo$19fto$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 02:53:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="304fb7f1a3d179ed34c480aa1b57821f";
logging-data="1359800"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+f7JfZCgOKLES1DP0ImA6SNC0zSDMcuAM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JldYdVEAv30BjN8Jjtg4JSFlgUk=
In-Reply-To: <ud3154$13irg$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Mon, 4 Sep 2023 02:53 UTC

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.

Re: What a bug

<ud3hag$19h7u$1@dont-email.me>

  copy mid

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

  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....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Sun, 3 Sep 2023 20:01:36 -0700
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <ud3hag$19h7u$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 03:01:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbfec9bf80a1760bb972bf83cd8a0103";
logging-data="1361150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vIvigO4sJUelJUddQg3uosgJaRQd0Vs4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:iXxPzO1g/J9oiGdYlUtQRCVFkkE=
In-Reply-To: <ud3gqo$19fto$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 4 Sep 2023 03:01 UTC

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.

Re: What a bug

<ud3o78$1acb6$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 4 Sep 2023 06:59:22 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <ud3o78$1acb6$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 04:59:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="304fb7f1a3d179ed34c480aa1b57821f";
logging-data="1388902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Gfq6/ADYcKar8hutSEhSMjliDHscGfxU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YVj54ciSTuk/pjZWwuEfwOy8ERw=
Content-Language: de-DE
In-Reply-To: <ud3hag$19h7u$1@dont-email.me>
 by: Bonita Montero - Mon, 4 Sep 2023 04:59 UTC

Am 04.09.2023 um 05:01 schrieb Chris M. Thomasson:

> A view into strings stored on the stack.

string_view is just a pointer and a size_t or two pointers.
And string_view is often faster since its constructor is
constexpr. If you do a string_view( "hello world" ).length()
that's all compile-time evaluated.

Re: What a bug

<ud470r$1cfbk$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 4 Sep 2023 11:11:55 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <ud470r$1cfbk$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>
<ud3o78$1acb6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 09:11:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="304fb7f1a3d179ed34c480aa1b57821f";
logging-data="1457524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MgUNpO6LuswfdI6+W5dx30NQuhlEYVqc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:O1iWp9MfFTS+tU0+rGwqgPH8BSc=
In-Reply-To: <ud3o78$1acb6$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Mon, 4 Sep 2023 09:11 UTC

Am 04.09.2023 um 06:59 schrieb Bonita Montero:

> string_view is just a pointer and a size_t or two pointers.
> And string_view is often faster since its constructor is
> constexpr. If you do a string_view( "hello world" ).length()
> that's all compile-time evaluated.

#include <string_view>

size_t fn()
{ return std::string_view( "hello world" ).length();
}

MSVC:

?fn@@YA_KXZ PROC
mov eax, 11
ret 0
?fn@@YA_KXZ ENDP

clang++:

_Z2fnv:
movl $11, %eax
retq

g++:

_Z2fnv:
movl $11, %eax
ret

Re: What a bug

<VMlJM.780913$mPI2.515002@fx15.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
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> <ud3154$13irg$2@dont-email.me>
Lines: 36
Message-ID: <VMlJM.780913$mPI2.515002@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 04 Sep 2023 14:24:53 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 04 Sep 2023 14:24:53 GMT
X-Received-Bytes: 1786
 by: Scott Lurndal - Mon, 4 Sep 2023 14:24 UTC

"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.

Re: What a bug

<U4tJM.421219$Fgta.289098@fx10.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.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>
From: pauldont...@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: <ucud4u$a111$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 32
Message-ID: <U4tJM.421219$Fgta.289098@fx10.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Mon, 04 Sep 2023 22:44:04 UTC
Date: Mon, 4 Sep 2023 18:43:52 -0400
X-Received-Bytes: 1603
 by: Pavel - Mon, 4 Sep 2023 22:43 UTC

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.

If you cared about the speed, why did you use unordered_map?

Re: What a bug

<ud5t77$1m72s$1@redfloyd.dont-email.me>

  copy mid

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

  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....@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 4 Sep 2023 17:36:54 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <ud5t77$1m72s$1@redfloyd.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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 5 Sep 2023 00:36:55 -0000 (UTC)
Injection-Info: redfloyd.dont-email.me; posting-host="d20635356993ec010e7bea674a488e74";
logging-data="1776732"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y8QxaAuXqIH1MXRmizwrpJcl3B2v+tYE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:qPPmxYB/FQLoqkowvLwqA1inND4=
Content-Language: en-US
In-Reply-To: <U4tJM.421219$Fgta.289098@fx10.iad>
 by: red floyd - Tue, 5 Sep 2023 00:36 UTC

On 9/4/2023 3:43 PM, Pavel wrote:
> 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.
>
> If you cared about the speed, why did you use unordered_map?
>

Yeah. For something done exactly once, with 5 entries, best bet is a
std::array.

Re: What a bug

<ud61e7$1qed6$2@dont-email.me>

  copy mid

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

  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....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Mon, 4 Sep 2023 18:48:55 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <ud61e7$1qed6$2@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 5 Sep 2023 01:48:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9f414e57f3965c384e999b1d5e124586";
logging-data="1915302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19st7EVPIETLNgCODFnjD/qA+ahdVF1OSQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Ve5VYmiXBJWGjVSH5oAy5X+s3Mc=
In-Reply-To: <ud3hag$19h7u$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Tue, 5 Sep 2023 01:48 UTC

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

Re: What a bug

<ud68h1$1r8t7$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What a bug
Date: Tue, 5 Sep 2023 05:49:54 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <ud68h1$1r8t7$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 5 Sep 2023 03:49:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e3dcd7ff00e37181b9b9938002eec9d6";
logging-data="1942439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vkknvdv/XgyXVqxVAYY8Fhs8IHS/xnrY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:eqEeJINqpOSYtCWrxNTFqZGpy34=
Content-Language: de-DE
In-Reply-To: <U4tJM.421219$Fgta.289098@fx10.iad>
 by: Bonita Montero - Tue, 5 Sep 2023 03:49 UTC

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,
which may result in a memory allocation. Depending on the case, this may
be too slow.


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

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor