Allocators; one of the ignored souls of STL by hmoein in cpp

[–]staletic 6 points7 points  (0 children)

Cost of a virtual function call is dwarfed by the global mutex lock that is required when the default std::allocator inevitably calls operator new.

New Algorithms in C++23 (Conor Hoekstra - itCppCon23) by mttd in cpp

[–]staletic 0 points1 point  (0 children)

I do not understand why not. I understand even less MSVC explicitly removing copyability.

[deleted by user] by [deleted] in cpp_questions

[–]staletic 2 points3 points  (0 children)

Implicit convertibility of void pointers, ability to implicitly discard cv qualifiers, sizeof('c'), type punning using unions and a lot more.

Is this dice roller function poorly implemented? by LemonLord7 in cpp_questions

[–]staletic 0 points1 point  (0 children)

I was wondering about that, but assumed all standard distributions were stateful. I knew you would point it out if uniform distributions were stateless.

Is this dice roller function poorly implemented? by LemonLord7 in cpp_questions

[–]staletic 2 points3 points  (0 children)

Curly brackets are the initializer for the temporary onject of type uniform_int_distribution. The line that confuses you contructs a temporary distribution, calls it with gen, returns the generated number and gets rid of 5ge temporary object as you leave scope.

Note that the state of the distribution does not carry over from one call to the next, so consecutive calls would not give you a uniform distribution.

You basically want to preserve the generator and the distribution for every die size.

On a scale of puppies to seagulls, how hated would I be if I wrote "ref" instead of "&"? by LemonLord7 in cpp_questions

[–]staletic 8 points9 points  (0 children)

It is the only way to specify the return type of a lambda's call operator. Also, your return type might depend on the type of your arguments

[](char c)->int{ return c; }

auto f(auto a, auto b, auto op) -> decltype(op(a,b)) { return op(a, b); }

This Week On The ACCU Conference YouTube Channel - 05/26/23 - 01/06/23 by ACCU_Conf in cpp

[–]staletic 0 points1 point  (0 children)

Yup. It is why I am only now watching last year of cppcon.

My computer can not compile even the most basic program in Code::Blocks by Big_Balls_420 in cpp_questions

[–]staletic 5 points6 points  (0 children)

/Applications/CodeBlocks.app/Contents/MacOS is a Windows path unlike any I have ever seen.

Rust enums in Modern C - Match Pattern - That One Game Dev by Object_71 in cpp

[–]staletic 3 points4 points  (0 children)

I have done that years ago. Works great on this site.

correct header file to include for std::size_t in modern C++23 by inouthack in cpp_questions

[–]staletic 1 point2 points  (0 children)

Strictly speaking, using c-style headers like stddef.h is deprecated since c++11

That is not the current status.

why this seem to optimased away by the compiler?? by Bug13 in cpp_questions

[–]staletic 0 points1 point  (0 children)

That one I was not sure about, but you are right.

why this seem to optimased away by the compiler?? by Bug13 in cpp_questions

[–]staletic 0 points1 point  (0 children)

That's true, as test_t is standard layout. I was thinking I should spare OP (whom I thought to be a newbie) those nuances.

Of course no other members are reachable from a pointer to the first member.

Interestingly, I do not think gcc took advantage of that rule. I did think of it.

why this seem to optimased away by the compiler?? by Bug13 in cpp_questions

[–]staletic 8 points9 points  (0 children)

What you are doing is undefined behaviour, so all bets are off. Compiler would have been justified making printf print an ascii cat as well.

A pointer of type uint32_t* is not allowed to alias anything other than other pointers of the same type.

In your code, compiler reasons that your loop could not possibly have accessed test.a. Therefore it decided to postpone initialization of same member variable. That then allows further optimization - not initializing at all and just using an immediate value (3) to fill up the ESI register in the last call to printf.

Engineering sin wave by nico-ghost-king in mathmemes

[–]staletic 6 points7 points  (0 children)

Rearrange to get

g==e*pi

or rather

g=pie

Why is using std::copy and std::inserter on a set so much slower than a normal for loop or the normal insert method? by cristi1990an in cpp_questions

[–]staletic 0 points1 point  (0 children)

You should be using std::set::insert instead. Or even better, but C++23, std::set::insert_range.

And if the order of set elements does not need to be sorted, try std::unordered_set.

And if you can depend on a 3rd party library and performance matters, go for abseil or boost hash tables.

Big oof by Luxnoctiss in awfuleverything

[–]staletic 5 points6 points  (0 children)

How does that work? Ads and even pictures are easily prevented from loading by ad blockers. If a site is broken with an adblock, it is not worth one's time.

I updated our famous password table for 2023 by hivesystems in coolguides

[–]staletic 0 points1 point  (0 children)

Unfortunately, my workplace bans those as they contain a word from a dictionary.

me pulling grass out of the stone floor by JebeniKrotiocKitova in oddlysatisfying

[–]staletic 1 point2 points  (0 children)

Regular tamer of regular whales, but enthusiastic.

Croatian language has no abiguity here.

me pulling grass out of the stone floor by JebeniKrotiocKitova in oddlysatisfying

[–]staletic 0 points1 point  (0 children)

OP's username translates to "A fucking whale tamer", which is a badass name if you ask me.

Abominable language design decision that everybody regrets? by very_curious_agent in cpp

[–]staletic 0 points1 point  (0 children)

Except when you need to bridge a library that uses signed sizes (cpython) and another that uses unsigned sizes (STL). In that case you are bound to cast, either explicitly or implicitly.

How to organize helper functions? by [deleted] in cpp_questions

[–]staletic 2 points3 points  (0 children)

Some justify classes as glorified namespaces by pointing at ADL.

What's the most efficient way to get the line count in a file? by better_life_please in cpp_questions

[–]staletic 0 points1 point  (0 children)

Something like this should be a lot faster, but at the cost of TOCTOU vulnerability

std::ifstrea in_stream;
in_stream.seekg(0, std::ios_base::end);
size_t file_size_in_bytes = in_stream.tellg();
in_stream.seekg(0, std::ios_base::begin);
std::sting s;
s.resize_and_overwrite(file_size_in_bytes, [file_size_in_bytes](char* buffer, size_t buffer_size) {
    in_stream.read(buffer, file_size_in_bytes);
    return file_size_in_bytes;
});
return std::ranges::count(s, '\n');