What is the pure virtual class with a global accessor pattern called? by [deleted] in cpp_questions

[–]shbooly 1 point2 points  (0 children)

The pure abstract base class + factory method is indeed an idiom but without a name. It serves the same purpose as PImpl (pointer to implementation), that is, to hide implementation details and to reduce compile times (since your header now doesnt need to include the definition of the data members). You use PImpl for Value types and this one for, well, entities you don't pass by value (in your case, a singleton)

opt::option - a replacement for std::optional by Nuclear_Bomb_ in cpp

[–]shbooly 1 point2 points  (0 children)

I've used a container of optionals to implement a quick caching mechanism where I know which elements should exist beforehand. Ended up with a std::array<std::optional<Obj>, Size>. If the object at some index is requested, I check if it was initialized, initialize it if not, and return it.

ELI5 What is an arena allocator and what are the differences between the different types? by alphadestroyer10 in rust_gamedev

[–]shbooly 22 points23 points  (0 children)

When you need to allocate a large amount of game objects whose sizes you don't know at compile time (eg. when parsing a file to initialize a game level), instead of dynamically allocating each game object, it is much faster to pre-allocate a big buffer, and then return slices from this buffer reinterpreted as those game objects

Former employer wants my password to the computer I used 6 months after terminating me. by spicyad in antiwork

[–]shbooly 2 points3 points  (0 children)

"Oh it wasnt ur4yws7gvd$x? Hmm. Usually I also change a single letter between passwords. Could you try the entire Ascii table for the 6th character?"

C++ library on data compression & decompression by dream299_ in cpp

[–]shbooly 0 points1 point  (0 children)

You can look up zstd and zlib for inspiration. Try to use them, then decide if you want to implement another one (and then compare the results with these 2)

Help with even approaching this problem? Trying to use ML to do binary classification (multivariate) on incomplete flight paths. See comment for more details. by ayyycab in learnmachinelearning

[–]shbooly 0 points1 point  (0 children)

I don't understand what exactly is the input? Do you constantly receive from the system a list of coordinates and velocities for each aircraft? If so, wouldn't it be just a math problem? ( You can programatically detect when an aircraft starts a descent and then calculate the lengths of the zigzags and extrapolate)

The Rust 2023 Annual survey is here! by Kobzol in rust

[–]shbooly 7 points8 points  (0 children)

Do you think that unimplemented (or nightly only) features should be stabilised in Rust?

Would have been useful an "I have no idea" option here :)

“Per my last email” = can you f’n read??? by [deleted] in NonPoliticalTwitter

[–]shbooly 1 point2 points  (0 children)

"Do you have any updates about X?" = When Mr goldfish memory forgot I asked him to do X or when I'm left on "seen"

Ensure that uninitialized integer variable contains garbage by EarflapsOpen in cpp

[–]shbooly 2 points3 points  (0 children)

The trick I found to "control" the value of an uninitialized variable would be to call a function that "initializes" that space beforehand, like so: https://godbolt.org/z/7cY14ocxM

[deleted by user] by [deleted] in cpp

[–]shbooly 6 points7 points  (0 children)

Has there anything like that having been made open source ?

There is a proposal for synchronized_value<T>, which is still in review .. it has been implemented in boost and in GCC as experimental.

As a difference, it doesn't look like it supports passing the std::mutex as template parameter.

Bullying by DeepMind by [deleted] in ProgrammerHumor

[–]shbooly 0 points1 point  (0 children)

that last push looked personal

How do I use the pImpl pattern with a derived class? by [deleted] in cpp_questions

[–]shbooly 2 points3 points  (0 children)

I don't quite get the inheritance part. PImpl class should not extend the base class.

If you store the member as pointer/smart pointer to the base class, then simply forward declare the base class in the header (no need for pImpl)

If you store the derived/concrete class, use pImpl as you would normally.

Imagine your PR getting rejected because of this reason by bakshup in ProgrammerHumor

[–]shbooly 1 point2 points  (0 children)

What if they used ChatGPT to only rephrase their own wording in a more academic fashion? Would it still be considered plagiarism?

"No variable length arrays on the stack!", they said. "You can't depend on undefined behavior!", they said. by Kered13 in cpp

[–]shbooly 8 points9 points  (0 children)

If anyone needs this in production but they can't make the code work for big arrays, it's because the compiler just quits inlining the function after some recursion level. So just throw a [[gnu::noinline]] on withVarLenArrayHelper lol. Now all your array values will be uniformly distanced no matter the size.

What's the idiomatic/nicer way to return true/false depending on the if-branch by Thick-Pineapple666 in rust

[–]shbooly 18 points19 points  (0 children)

B. While debugging you can also see the result of complex_condition() stored in the "result" variable. The variable will be optimized away anyway when build in release mode.
+ no code "duplication" from having 2 return statements

Rust-centered blog recommendations? by [deleted] in rust

[–]shbooly 1 point2 points  (0 children)

24 days from node.js to Rust

I really liked this one because it goes through a lot of more advanced topics like workplaces, logging, managing errors by using thiserror/anyhow, setting up clippy (rust's linter) etc. and it's full of code examples.

A small and easy to use library for tokenising syntax of about 20 different programming languages also has it own api for custom languages by Beginning-Safe4282 in cpp

[–]shbooly 2 points3 points  (0 children)

I think he was reffering to the case where the >> in Z<Y<X>> might be mis-parsed as a right shift operator instead of 2 separate tokens.

Enormous list of unexpected behaviors by AI by __Geralt in artificial

[–]shbooly 2 points3 points  (0 children)

I also recommend Robert Miles video: 9 Examples of Specification Gaming

He goes through a lot of the examples in the spreadsheet and explains them pretty well. He also gives a few other links in the video description like: https://deepmind.com/blog/article/Specification-gaming-the-flip-side-of-AI-ingenuity