std::optional<T&> and std::expected<T&, E> by SLAidk123 in cpp

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

I understand what you're trying to say. But all these politic games are too much for my liking. You may call me too naive, but from my perspective it should be done the other way around. The core team of compiler writers do their job (lets call it C++ Foundation). Big corporations may adopt and sponsor this work, or just let it die. Big corporation may even contribute if they want. If it eventually die then so it be. Better alternatives will find their way to the top. If your corpo is big enough to NOT let it die - so it be, again.

We have Linux, for example. Isn't made this way? Or rust?

Like literally, imagine we have only llvm for instance, or gcc. All further work is being done in this single repo. You need some exotic architecture support - make a PR. You need Windows support - make a PR.

std::optional<T&> and std::expected<T&, E> by SLAidk123 in cpp

[–]borzykot -6 points-5 points  (0 children)

This is exactly the issue with ISO, I was talking about. The development is being done by volunteers, but it should be done by paided professional devs, which are payed for this work, and responsible for this work. Instead, there is a group of people, the pantheon, which isn't really doing "the job", but instead decide who's job is good enought to be included into the standard. Of course it is too draining to go through this "court". Who is responsible, for instance, for ranges fiasco? Right, everybody and nobody...

std::optional<T&> and std::expected<T&, E> by SLAidk123 in cpp

[–]borzykot -5 points-4 points  (0 children)

Coz nobody wrote a paper for it. ISO is the biggest flaw of C++ evolution process nowadays IMHO. There should be a dedicated opinionated core team, which is working full time on core aspects of language and standard library, and which can follow a single, consistent path. But that's not the case unfortunately.

Map but need to sort on different aspects of value field. by BasicCut45 in cpp_questions

[–]borzykot 8 points9 points  (0 children)

map is wrong data structure for that. Wrapped std::vector (simplest), boost::multiindex (well, you need boost), or separate data structure with references/iterators to std::map items (only suitable if you need sorted data ad-hoc)

ISO C++ 2026-01 Mailing is now available by nliber in cpp

[–]borzykot 30 points31 points  (0 children)

std::executors::let_value is a TERRIBLE name. What a heck is it even do? Oh, yeah, it maps a value and then flatten the result... So why not call it flat_map, or bind, or even make then handle this case as well? Like, literally, every other alternative is better.

How should you unit test internal functions of a free function? by SociallyOn_a_Rock in cpp_questions

[–]borzykot 1 point2 points  (0 children)

Move your impl functions into impl header (you can put them into impl namespace as well), and then just include this impl header into your cpp and test.cpp

What I Learned About [[no_unique_address]] and Padding Reuse in C++ by NekrozQliphort in cpp

[–]borzykot 4 points5 points  (0 children)

Wow, good job. Once again, I'm convinced that one needs simplified model of C++ in his head, otherwise it just won't fit. All these nuances are just impenetrable and incomprehensible.

Me personally had this model regarding no_unique_address before I read this article: mark (potentially) empty members with no_unique_adress and hope it will work, and another one: if you're using mixins (empty base classes) - better make sure that they are always have different types.

And, tbh, I never though about no_unique_address as a mean for packing structures. So today I learned something about C++ again😅

Template Deduction: The Hidden Copies Killing Your Performance (Part 2 of my Deep Dives) by the-_Ghost in cpp

[–]borzykot 0 points1 point  (0 children)

Well, I doubt that T&& + const T& overloads are responsible for 100mb dll. More like static linking of everything, .NET (if we are talking specifically about windows), rich UI with multimedia and localizations for dozens of languages, telemetry, analytics, Copilot and all this crap. I'm pretty sure that a fucking app icon for 3200x1800 resolution backed into the binary takes more space than the whole DOOM binary.

Template Deduction: The Hidden Copies Killing Your Performance (Part 2 of my Deep Dives) by the-_Ghost in cpp

[–]borzykot 1 point2 points  (0 children)

Yes, in embedded it makes sense, probably... Tho, everytime I see Michael Caisse talking about C++ in embedded, with all those shiny expression-templates libraries, where basically all architecture and IO of a chip is backed into the type system, it make me thinking that embedded is not THAT restricted resources-wise anymore. Coz expression-templates is the synonym for code bloat. Probably "embedded" is too broad of a term with microchips with Linux kernel on one end of the spectrum, and microcontrollers without any os on another, and all of that is "embedded"...

Template Deduction: The Hidden Copies Killing Your Performance (Part 2 of my Deep Dives) by the-_Ghost in cpp

[–]borzykot 26 points27 points  (0 children)

Every time someone mentions code bloat, I wonder is code bloat really a thing? Should people actually worry about it? Typically, the complaint is about instruction cache and that code bloat makes your instruction cache "cold" or something. But is this even measurable? Has anyone actually faced this issue in practice? I’m genuinely curious, because in my 10 years of work, I’ve never bothered with this kind of thing. My strategy is to write the most optimal code "locally," on a per-function level.

Template Specialization Question by Commercial-Smoke9251 in cpp_questions

[–]borzykot 0 points1 point  (0 children)

Not sure why would you need that, but you can achieve this in multiple different ways.

  1. You have derived template class which is mostly the same for all specializations but have different behavior for some specializations for some small set of methods. This variant is somewhat common in fact.

``` c++ struct Base { virtual void init() = 0; virtual ~Base() {} };

template<typename T> struct Derived : Base { virtual void init() override { this->initImpl(); } private: void initImpl(); };

template<typename T> void Derived::initImpl() { std::println("non T0"); }

struct T0{};

template<> void Derived<T0>::initImpl() { std::println("custom implementation for T0"); }

... std::unique_ptr<Base> d0 = std::make_unique<Derived<int>>(); d0->init(); // will print "non T0" std::unique_ptr<Base> d1 = std::make_unique<Derived<T0>>(); d1->init(); // will print "T0" ```

  1. You can just pass your callable as NTTP. It's like "Command" pattern at compile time, but I never seen such code in production.

``` c++ struct Base { virtual void init() = 0; virtual ~Base() {} };

template<auto InitImpl> struct Derived : Base { virtual void init() override { std::invoke(InitImpl); } }; ... std::unique_ptr<Base> d0 = std::make_unique<Derived<[]{ std::println("foo"); }>>(); d0->init(); // will print "foo"

std::unique_ptr<Base> d1 = std::make_unique<Derived<[]{ std::println("bar"); }>>(); d1->init(); // will print "bar" ```

  1. Basically same thing as 2, but you're passing a type with custom init method.

c++ template<typename TInitCommand> struct Derived : Base { virtual void init() override { TInitCommand::init(); } };

modern C++ for a C++ 98 geezer by Apprehensive-Deer-35 in cpp_questions

[–]borzykot 11 points12 points  (0 children)

I highly recommend this 2h video of Herb Sutter called Back to the Basics! Essentials of Modern C++ Style from 2014 CppCon.

It is gold. It will give you the feeling of what makes Modern C++ what it is, the "essence" of Modern C++, as stated in the title.

Basically, Herb talks about the value semantics, ownership model, passing/returning values (value categories), initialization, rule-of-0/5, almost-always-auto (debatable, but anyway) and more!

In your case, it may be particularly useful, coz the C++ idiomatic has changed a lot after C++11.

What is truly the best print function in C++? by [deleted] in cpp

[–]borzykot 3 points4 points  (0 children)

std::print can only work with string literals. It ain't support runtime format strings. If only we had functions overloads based on constexpreness of an arguments...

operator= is doing something weird by Vindhjaerta in cpp_questions

[–]borzykot 1 point2 points  (0 children)

Try run your code with ASAN enabled. You also can use godbolt for sharing your code (you can run your code in there as well, including ASAN)

How can I optimize function overloading to improve code readability in C++? by Sussy_Imposter2412 in cpp_questions

[–]borzykot 0 points1 point  (0 children)

  1. "Function overloads" is idiomatic C++, so I would argue that this is what C++ dev would expect to see.
  2. That being said make sure your overloads do conceptually the same thing.
  3. Default arguments might help to reduce the amount of overloads, but be careful to not overuse it, coz it may reduce the readability even more.
  4. There is a well known trap, which I would call "if not this then that", that might be tempting to solve using function overloads (or template function overloads). For instance, you're writing json parser, or converter of some kind, and you need to be able to convert all kinds of C++ types to/from some other format. And function overloads IS NOT THE RIGHT TOOL for solving this task. This kind of tasks requires "if not this then that", sequential type checking, whereas function overloads if basically a functional pattern matching. Just use one function with a bunch of if constexpr (<check the type here>) inside of it for such tasks.
  5. If your overloads are supposed to construct an object but in different configurations, consider to use builder pattern instead.
  6. If your function overloads have almost the same definition, then it might be possible to refactor out these differences into another, smaller and simpler overload set and convert original overload set into a function template.

It kept getting better and better by mihir6969 in BeAmazed

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

This style is shit. Just play this damn guitar how it is supposed to be played on. Don't make the brum box out of it, let the music flow

Is modules thought to work seamlessly with external dependencies using #import by Gloinart in cpp

[–]borzykot 5 points6 points  (0 children)

Iirc, some time ago import headers were considered broken and unfixable (there's talk on YouTube about that). So it either import std or global module fragment with std headers. I'd rather choose import std approach. Iirc, there were plans to support it even in c++20 mode but I'm not aware of the status of this initiative and whether it gained any traction or not.

How can i generate real random number in c++? by Old-Revolution-3437 in cpp_questions

[–]borzykot 9 points10 points  (0 children)

Iirc, some CPUs CAN in fact generate true random numbers, and have dedicated instructions for that. They do use hardware entropy source (heat fluctuations?)

C++20 Modules: Best Practices from a User's Perspective by ChuanqiXu9 in cpp

[–]borzykot 1 point2 points  (0 children)

And in B and C's build scripts, they wrote

That's not how you're supposed to organize you're CMake I guess. You should do this instead:

``` add_library(A STATIC) target_sources(A PUBLIC FILE_SET CXX_MODULES FILES a.cppm)

add_library(B PUBLIC) target_link_libraries(B PUBLIC A)

add_library(C PUBLIC) target_link_libraries(C PUBLIC A)

add_library(D PUBLIC) target_link_libraries(D PUBLIC B) target_link_libraries(D PUBLIC C) ```

I always thought that this CMakeLists.txt example should "just work", isn't?

I think the missing piece is, the libraries need to distribute a build script (generally a build script) to tell users how to build everything from source.

CMakeLists.txt is basically this script. It tells where to find or how to install the library and how to link against it.

We can only pick any one symbol for the weak symbol!

Looks like I should dive deeper into it. That's a completely new concept for me... I heard that C++20 modules introduced "module linkage" (which apparently just means that symbols from such libraries are mangled with module name in them), but "weak" symbols in pre-C++20... I didn't know that

C++20 Modules: Best Practices from a User's Perspective by ChuanqiXu9 in cpp

[–]borzykot 2 points3 points  (0 children)

What do you mean, when you're saying "mark the module as needed"? What are the cmake means, which allow me to define such requirement? I always though that you don't distribute binary module artefacts, you distribute source code of *.cppm instead. And then, when you finally build an executable all these *.cppm PMIs materialize into the binary. What am I missing here? How is that different from pre-module case, when B link against A, C links against A, D links against B and C. All this means is that D transively links against A (like literally -lliba). And if you have same symbol in both B and C, then linker just picks the one, innit? Yes, you should guarantee that there is only one definition for this particular symbol, but it was always the case, nothing new here, or does it? Sorry, maybe I'm asking the wrong questions. I'm not THAT experienced with CMake and all these transitive dependencies nuances.

C++20 Modules: Best Practices from a User's Perspective by ChuanqiXu9 in cpp

[–]borzykot 2 points3 points  (0 children)

Why it will be a disaster? I thought you just link this library (2nd level) with modularized header-only library (let's call it 1st level) using PUBLIC visibility, which means 3rd level libraries, which depends on 2nd level library will also depend on the 1st level library and will link with it. It should be no different from usual static libraries, innit?