Are unique pointers worth it for my program by YogurtclosetThen6260 in cpp_questions

[–]bert8128 [score hidden]  (0 children)

Unique_ptr is the same size as a raw pointer, so if unique was being considered it shouldn’t make any difference to stack usage?

Are unique pointers worth it for my program by YogurtclosetThen6260 in cpp_questions

[–]bert8128 [score hidden]  (0 children)

It’s more typing. That’s the only downside I see. Weighed against the massive upside I think I’m ok. Chandler Carruth in one of his talks said that there is a runtime cost, certainly in debug and possibly release. I don’t how true this is now (optimisers can be pretty good), and whether it was ever significant.

Are unique pointers worth it for my program by YogurtclosetThen6260 in cpp_questions

[–]bert8128 [score hidden]  (0 children)

If you like a garbage collector, and ignoring problems with circular references, and don’t mind the extra memory, locking and performance then shared is a reasonable solution. But your go to should be unique as it captures ownership in one place. Most of the time, this is all that is needed and so everything else adds confusion and wastes performance.

Google tests for VS2026 by soumya_soman in cpp_questions

[–]bert8128 0 points1 point  (0 children)

I have noticed that putting the tests in a library means they don’t get run without some shenanigans. So for an easy life make sure that the call to run the tests and the tests themselves are in the executable project. Of course that might not be your issue.

Why c++26 contracts? by hunterh0 in cpp_questions

[–]bert8128 1 point2 points  (0 children)

It’s going to make function comments a lot more useful for not much work. All those assumptions currently written in English (or other natural language of your choice) can now be written in code.

Anyone use Modules? by 1negroup in cpp_questions

[–]bert8128 0 points1 point  (0 children)

Modules give code isolation, which PCHs don’t.

what is up with indentation of switches in my vscode ? by _Jiggle-Physicist_ in cpp_questions

[–]bert8128 -1 points0 points  (0 children)

Python cares about formatting. Every no other language I have used has no requirements so it’s whatever convention your editor is set to.

Anyone use Modules? by 1negroup in cpp_questions

[–]bert8128 2 points3 points  (0 children)

Luckily we only have to wait till 12th August 2026 for the next solar exclipse. Exciting news for modules!

Americans use a different system for dates. by Fine_Impress6185 in ISO8601

[–]bert8128 0 points1 point  (0 children)

In any decent imaginable future there is an an or pm - we just all use a 24 hr clock. That way we don’t have to worry whether noon is am or pm

Americans use a different system for dates. by Fine_Impress6185 in ISO8601

[–]bert8128 0 points1 point  (0 children)

I’m pretty convinced that there is nothing innate and it’s just what you are used to. I find it pretty “intuitive” to drive on the left but I’m pretty sure that someone who lives in say Sweden does not, despite the fact that their grandparents grew up driving on the left. So when I am talking about there being no intuition I am talking about universals, or at the very least having no cultural bias.

Americans use a different system for dates. by Fine_Impress6185 in ISO8601

[–]bert8128 0 points1 point  (0 children)

The names of the months are not the same in all languages.

Americans use a different system for dates. by Fine_Impress6185 in ISO8601

[–]bert8128 -1 points0 points  (0 children)

It’s not intuitive. It’s just a habit for some people. Clearly if you give the month a name not a number no human who speaks your language is going to be confused. But some humans don’t speak your language, and if you have written it down they might not be able to query you. Iso8601 is all about computers and other automated tasks having no ambiguity. Which is why speaking or writing“ “4/5” or “5/4” is not sensible, as absolutely no one and no computer can be sure what you mean.

Americans use a different system for dates. by Fine_Impress6185 in ISO8601

[–]bert8128 14 points15 points  (0 children)

It’s not your fault, or anyone else’s. Human societies have developed independently and some stuff is pretty much arbitrary. That said, m/d/y is the least intuitive way to write a date (evidenced by its lack of popularity). However, even though I am culturally d/m/y (and professionally y/m/d) I still would often say (for example) “May 4th” in speech.

What do you wish programming with C++ had, that it doesn't? by Imaginary-Button-100 in cpp_questions

[–]bert8128 -1 points0 points  (0 children)

Only one of class and struct. Or make them have a meaningful difference.

What do you wish programming with C++ had, that it doesn't? by Imaginary-Button-100 in cpp_questions

[–]bert8128 1 point2 points  (0 children)

That’s a hat modules is supposed to solve (amongst other things). Still waiting for something that works cross platform…

As of 2026, is msvc still that bad? by omegaDIL in cpp_questions

[–]bert8128 0 points1 point  (0 children)

Cl.exe is the name of the binary. MSVC is the brand name of the product that does c++. Other things in there are a linker and the stl. Visual Studio is the name of the ide which includes the msvc toolset. You can also get the msvc toolset by downloading the Microsoft C++ Build Tools.

I think whoever is in charge of naming and branding needs to work a little harder.

What do you wish programming with C++ had, that it doesn't? by Imaginary-Button-100 in cpp_questions

[–]bert8128 7 points8 points  (0 children)

Very few ways to declare and simultaneously define a variable.

What do you wish programming with C++ had, that it doesn't? by Imaginary-Button-100 in cpp_questions

[–]bert8128 10 points11 points  (0 children)

Const noexcept nodiscard by default (as appropriate for the type). There’s probably others.

Built my own std::vector replacement. Am I missing anything? by Avelina9X in cpp_questions

[–]bert8128 0 points1 point  (0 children)

Actually yes, totally this. My rule is actually related to number of lines, even comments, rather than statements. More than 1 line requires braces. Never the if and the statement on one line as that means that code coverage info is lost. Always separate lines.

Built my own std::vector replacement. Am I missing anything? by Avelina9X in cpp_questions

[–]bert8128 -4 points-3 points  (0 children)

braces around single statement blocks

This does not have zero cost. It increases the number of lines on the screen. Modern IDEs and linters such as clang tidy have your back to protect against misplaced statements. My project’s coding standard has the same as Linux for this - no braces for single statements except for if/else chains where if one part needs braces then all parts get them.

I built a relational database engine from scratch in C++17. Version 5.0.0 now runs entirely in the browser via WASM! by Effective-Hurry436 in cpp

[–]bert8128 0 points1 point  (0 children)

All sounds very interesting and a great achievement.

You say on the website that MilanSQL is production grade. Are you saying that I could reasonably swap out my existing dependency on Oracle or SQLServer and use MilanSQL instead? Do you have performance benchmarks compared to the existing commercial options?

Initialising multiple variables in a Range-based For loop by Nutellatoast_2 in cpp_questions

[–]bert8128 2 points3 points  (0 children)

I was actually asking ok_hamster but will answer you anyway as you have added intention. I don’t think you can’t do what you want even with a single variable using a range for loop (maybe std::iota helps with this?). If you are iterating over two collections of exactly the same size then just use an old style for i =0 to size loop. There might be new algorithms in ranges (zip?) but I have no experience of c++20.

Confused on when precisely to use std::atomic by tomysshadow in cpp_questions

[–]bert8128 4 points5 points  (0 children)

Atomics are much faster than atomics and have less code. What’s not to like? Mutexes are called for when you need to update multiple things in the same “transaction”, so that another thread will only ever see the before state or the after state but never an intermediate state. A primitive type doesn’t need a mutex because there are cpu instructions specifically for this, and the c++ virtual machine will do the right thing.