Sunday, September 3, 2023

Digest for comp.lang.c++@googlegroups.com - 2 updates in 1 topic

jak <nospam@please.ty>: Sep 03 11:17PM +0200

jak ha scritto:
> 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.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Sep 03 03:25PM -0700

On 9/1/2023 9:19 PM, Bonita Montero wrote:
 
>>      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.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: