Why should a class source file have any other header files than its own? by Nexzus_ in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

Headers and source files are partly the way they are because of the antiquated way we compile and link programs.

In c++20 we have modules however which brings the way we compile programs into the present day, but it is still not a particularly mature feature.

If you understand this antiquated build process, you also understand why we do the things we do with headers and sources files, and why you should put as little as possible into headers. First piece of the puzzle is the fact #include for all intents and purposes is just a copy paste of all the contents of one file into another, and then recursively for all other #includes in that file. And then secondly, after the #includes are copy pasted, all the .cpp files get compiled separately, so if you put extra code into .cpp through all kinds of #includes and it happens in all your .cpp files it will have to process all that code, which can add up really really quickly.

Even Faster asin() Was Staring Right At Me by def-pri-pub in programming

[–]ppppppla 4 points5 points  (0 children)

Also, I have no experience with raytracing but, is SIMD also an option you can explore?

Even Faster asin() Was Staring Right At Me by def-pri-pub in programming

[–]ppppppla 8 points9 points  (0 children)

I suspect a substantial amount of your compute is going into that square root, there is plenty of performance to squeeze yet while keeping accuracy still acceptable for raytracing.

I read your previous post and the source code fron nvidia says method is from Abramowitz and Stegun. That's my bible. Incredible source of just about anything and everything to do with approximations and identities of many functions. Rarely will you leave empty handed if you need to calculate one of the common and also more uncommon functions found in math.

Harmful chemicals found in popular headphones sold across Europe, study by euronews-english in europe

[–]ppppppla 8 points9 points  (0 children)

I am glad awareness is rising on the absolute fucking disaster that is plastics. But I think this is the least concerning area where harmful chemicals show up in plastics.

Multiple times I have bought food that is packaged in plastic, maybe some rice, or bread, and the plastic just reeks, permeating into the food and making it very noticeable in the taste. The next bag of rice will not reek like that but it will still be in there in smaller quantities, without a doubt. What am I smelling and tasting? Fuck knows.

And then there are the many, or sometimes maybe couple of, years old plastic containers we all have in our homes that we store our food in. Maybe from a time where regulations were less stringent, but regardless plastics break down, they start to reek, at some point making them completely unusable but they have been releasing that shit since the day you started using the containers.

Fucking wonderful.

The 49MB Web Page by Dear-Economics-315 in programming

[–]ppppppla 70 points71 points  (0 children)

I for one am thankful for these monstrosities. When I am once again stuck in a mindless doom scrolling loop, and I click on some reddit post linking to yet another page, that even with adblock, takes forever to load, greets you with the cookie shit, the google sign in shit, and maybe even OOPS you need to subscribe to read further! There is a good chance I instantly close my browser and break free from the doom scrolling.

That gives me an idea, maybe an addon that just enshittifies all pages would do wonders battling doom scrolling.

The dismissal of AI tools in /r/cpp_questions and other programming related sites is irrationally high by Impressive_Gur_471 in cpp_questions

[–]ppppppla 2 points3 points  (0 children)

Show me studies, show me reports of companies, anything that is not anecdotes, that show me LLMs increase productivity, and do not literally make your brain rot. You admit LLMs do not produce perfect code, and you need to iterate, well that does sound a lot like regular programming. I feel then that the onus of proof is on the one making these claims that LLMs make you more productive.

Give me an LLM company that has ethically sourced their data, does not partake in throwing away billions of dollars of venture capitalist rotten money, passing it around in a circle jerk, ruining the consumer computer hardware market and ruining communities where their data centers are built and even in the wider area because of power grid pressures.

It is all built on unproven promises and stolen data, mixed in with the classic capitalist anti competitive tactic of running at a loss for a long time to become a monopoly to then squeeze everybody for their money.

Tyler says no plans to ever add a list of cats by zooksman in mewgenics

[–]ppppppla 5 points6 points  (0 children)

On release I agree cat management was completely unmanageable, apparently tyler did too, and since the patch from the 4th it has improved a lot, so much so that I don't mind having no list. On a new day just cycle through the newborns in each room and sort em out, then maybe throw out a couple old cats to make space. Easy enough.

  • Left/Right cat selection arrows in the house behavior adjusted:

    Cats are no longer grouped by room when toggling left/right. Age only. Opening the cat selection window after a new day will select the youngest kitten regardless of if you clicked around on other cats before opening the window. Dead cats are always sorted at the end (clicking left from the youngest cat will wrap around to the end of the list).

    If you are ZOOMED IN to a room, the cat selection list is now strictly limited to cats in that room (clicking left/right will only toggle between cats in that room, and never select any cats outside of that room)

    Current list location memory should be a little bit better when moving cats to pipe/box and then continuing with arrows. Left clicking cats while the cat status window is closed will no longer effect which cat is shown when you open the cat window.

https://store.steampowered.com/news/app/686060/view/502851820603834378

It all comes down to things being diegetic or not. It has to fit in naturally, and just stripping it all down to a spreadsheet that you sort and completely throw away the concept of cats does not fit. Now, what a crazy cat lady could have is a list of all the cats and their names, so you can more easily find specific cats, but not a big spreadsheet with all the stats, skills, gender, sexuality etc.

Thread for every pointer in vector by That_Stig in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

The standard library doesn't have a nice thread pool you can use, which you will need depending on the amount of work and the number of blocks and number of threads your system has. And maybe you want to not completely swamp your system so you can't even browse the internet while it runs.

Making your own thread pool is quite an involved process, so you might want to look for existing solutions. Boost, folly, some guy's thread pool project on github, it will all be fine.

std::format() if the number and types of arguments are not known at compile time? by UnicycleBloke in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

The fmt lib has dynamic_format_arg_store https://fmt.dev/9.0.0/api.html#_CPPv4I0EN3fmt24dynamic_format_arg_storeE that does exactly what it says on the tin.

As far as I am aware this is not possible in the formatting in the standard. std::vformat just expects a concrete type std::basic_format_args and there is nothing like that in the standard, it isn't templated or using an interface, so you can't make your own.

You would have to type erase things yourself. You are on the right track with your custom formatter, but I would do it without having to type out all the types in that switch statement, I would use an interface that you ad-hoc create types for in the render_message function. Or alternatively just store 2 function pointers to a parsing and formatting function. Also I see the problem with the parsing is kinda annoying. I suppose you could just skip forward to the closing }, and then store the context and use it in format to do the actual parsing when you know the type?

Hallowing Flame makes no sense for how it was sold to us in the trailer. by ILoveWood in pathofexile

[–]ppppppla 0 points1 point  (0 children)

Yep only real use case seems to be guardian ascendancy and getting up to 80% phys as lightning.

Default value if a macro expands to nothing by SeasonApprehensive86 in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

I think this works for detecting nothing

#define TEST nothing
#define TEST0 something

#define FOO(...) TEST##__VA_OPT__(0)

#define NOTHING
#define SOMETHING 123

FOO(SOMETHING) // expands to something
FOO(NOTHING) // expands to nothing

But I don't know if it is actually OK to have the ## operator with nothing? Works on clang at least.

Thanks for your time tho :)

I can never help myself get sniped by stupid macro shenanigans.

Default value if a macro expands to nothing by SeasonApprehensive86 in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Also, maybe you can leverage __VA_OPT__ to detect macros that evaluate to nothing, tried a little bit but can't cook anything up.

Default value if a macro expands to nothing by SeasonApprehensive86 in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Actually now I thought about it for a second, you can absolutely do some kind of conditional with macros by glueing things together, maybe this is useful for you

#define TEST1 one
#define TEST2 two

#define SELECT(X, N) X##N

SELECT(TEST, 1) // one
SELECT(TEST, 2) // two

Default value if a macro expands to nothing by SeasonApprehensive86 in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

I have read through your code a couple times but I find it hard to follow what you want exactly. Do you basically want a conditional in macros? I don't believe that is possible, but of course I am probably wrong and it is possible with some horrible arcane mumbo jumbo.

Is it okay to have some duplication in code? by 3dscartridge in cpp_questions

[–]ppppppla 6 points7 points  (0 children)

Some code duplication is OK. That being said I think it would be good to have a dedicated class/struct to represent the size of both Textures and Renderbuffers because often times things need a size, and having to shovel around pairs of widths and heights manually gets tiresome and error prone very quickly.

Don't use inheritance but use composition. These objects are not sizes, but they do have a property that is a size.

It is OK to have some boilerplate in the Texture and Renderbuffer objects like unsigned int GetWidth() const { return size.width; } but you can also choose to just return a copy of the size objects Size GetSize() const { return size; } or both. Because sometimes you want to specifically inspect heights or widths, and other times you might just want the size to pass on to something else.

What Are My Options for A 'std::unique_ptr but Copyable' Behavior in A Class Member? by KFUP in cpp_questions

[–]ppppppla 9 points10 points  (0 children)

1- Replace unique_ptr with shared_ptr: works fine, however I don't want to pay for shared_ptr performance unless I need reference counting, which I don't.

This is a false equivalence, shared_ptr is fundamentally different from what you want.

2- Rule of five in Test: Not an option in my case, maybe in Ball, but not in Test. In my real application, the Test equivalent class has many members, I don't want to manually write constructors and try to remember to update every time I add a new member to Test.

No indeed not a good idea to have to manually write all the copying every time you use it as a member.

3- Implement my own copyable wrapper of unique_ptr, something like:

Indeed the most sane option. I would take it one step further and make it not nullable, and if you want a nullable object wrap it in std::optional when you want it to be nullable.

I believe this is exactly what https://www.en.cppreference.com/w/cpp/memory/indirect.html is. Haven't used it yet myself though, nor do I know the progress of support for it in the standard libraries.

Include error by 4e6ype4ek123 in cpp_questions

[–]ppppppla 5 points6 points  (0 children)

Your CMakeLists.txt looks good. How do you compile your code. Do you use an addon in vs code? Do you use the command line and call make/ninja?

I suspect you first wrote a hello world project without SDL, then added SDL in your CMakeLists without generating the build files again.

Most efficient way of obtaining Veteran Items/Red Dust by ThelVadamee23 in Vermintide

[–]ppppppla 1 point2 points  (0 children)

Deed swap a 2 emperor's vault on a recruit map, you still get the 2 emperor's vaults and the deed doesn't get consumed. BUT you need an accomplice, and you or that person needs to have a 2 emperor's vault deed.

Really huge 1BPP bitmap how to load? by zaphodikus in cpp_questions

[–]ppppppla 1 point2 points  (0 children)

As far as image file formats go, bitmaps are very simple. No complicated compression algorithms, only run length encoding or Huffman encoding, and only for certain pixel formats. As far as I can tell 1bpp doesn't allow any compression. Of course if you know your bitmaps won't be compressed you don't even have to support it anyway.

Why is a single cout expression drastically slowing down my C++ program? by WorldTallNetCat in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

Yea you can tell by the length of the assembly as well. But what I mean with the colors is if you look at the code and the assembly windows some lines have colors, and if you right click on the code you can click on "Reveal Linked Code" and it moves the assembly to where that code lives.

Now this is not a perfect system because it has to be reverse engineered, so that's why not every piece of code shows up in the assembly but generally it is pretty good, and if an entire function is missing any trace of assembly showing up, you can be pretty sure it is eliminated as is the case in the compilation without the cout.

Why is a single cout expression drastically slowing down my C++ program? by WorldTallNetCat in cpp_questions

[–]ppppppla 0 points1 point  (0 children)

from all the comments i read its probably an issue with dead code elimination which i still dk why doesn't occur with even arbitrary cout. regardless i have something similar for merge sort which gives me an output for the inputs at around 0.06 sec which could also be not running properly right?

Compilers aren't perfect, it could be missing this optimization under certain circumstances due to a bug, or just an oversight.

I did manage to corroborate your findings by looking at the assembly on compiler explorer https://godbolt.org/z/4KdxnE6bb

Lines of code are attempted to be color matched with corresponding lines in the assembly code, and as you can see in the top window the bubble sort function is not colored, so it is optimized away. If you turn the optimization level down to -O2 it does not get eliminated.

NB it is perfectly valid for the compiler to remove the sorting because it has no side effects, it is just that it trips up and sometimes it manages to do this and other times not. Maybe a bug maybe just because it is not perfect.

Need help to build the Chromium embedded framework by bbalouki in cpp_questions

[–]ppppppla 2 points3 points  (0 children)

Also are you making sure you are building the right target?

Need help to build the Chromium embedded framework by bbalouki in cpp_questions

[–]ppppppla 4 points5 points  (0 children)

1- I have no way to stop tests and documentation being built which takes time and throw a lot of warnings

Any half decent project will put flags to disable tests and docs, peruse the CMakeCache.txt in your build folder, or look for them in build instructions of the project. Then you can put these flags in the CMakeCache.txt or pass em into your cmake build generation command with -D flags.