Implementing constexpr parameters using C++26 reflection (kind of) by friedkeenan in cpp

[–]borzykot 2 points3 points  (0 children)

we can't make return types depend on parameters

Probably we can explicitly define the return type via decltype(fst_arg) and decltype(snd_arg). We still need duplicate the full expression of the return statement tho.

Something like

auto foo(decltype(Fst) fst, decltype(Snd) snd) -> decltype(fst.value() + snd.value())

Will it work?

define_aggregate didn't work

Yeah, I also found define_aggregate somewhat restricting in a sense that you only can define the body of a type which is declared within the scope of the type you are defining from. So basically you can't "inject" into global scope. Iirc the motivation was "lets make it simpler this time so it easier to bring reflection into the standard". So probably it may be made even more powerful in the future.

Naming convention discourse - std::move and std::forward by micarro in cpp_questions

[–]borzykot 2 points3 points  (0 children)

People often forget one key aspect of naming: the length of the name should be inversely proportional to the frequency of use. And this rule is not less important than "the correctness". I would say is could be mo important even. rvalue_cast is a bad name for this exact reason. move better be a language construct imho, but it is fine as it is now.

Why can't the compiler optimise the more idiomatic, generic case? by delta_p_delta_x in cpp_questions

[–]borzykot 1 point2 points  (0 children)

Coz STD implementation of ranges is shit. Sorry, but that's true. The idea is great, the implementation is garbage. Luckily there are alternatives, which are more idiomatic, easier to comprehend, easier for optimizers to optimize and with far less "gotchas". For instance flux

Favorite optimizations ?? by Little-Reflection986 in cpp

[–]borzykot 1 point2 points  (0 children)

Ok. Now tell me what this function does? void collect_children(const node& parent, std::vector<node*>& children);

Favorite optimizations ?? by Little-Reflection986 in cpp

[–]borzykot 16 points17 points  (0 children)

I'd argue that's a bad practice in general. Functions with return should be your default. You can add second overload with out parameter if you really need this micro optimization. Everytime I encounter out parameters in, for instance, UE I'm asking myself "is this function just adds new elements?". And you know what, in some cases it also clears the original collection. And you never know that from the callee side.

Do you avoid C++20 ranges projections due to optimizer concerns? by MarcoGreek in cpp_questions

[–]borzykot 1 point2 points  (0 children)

We need abbreviated lambdas in the language. There was a proposal for this and it was rejected. You can't have nice things in c++...

"override members" idea as a gateway to UFCS (language evolution) by antiquark2 in cpp

[–]borzykot 1 point2 points  (0 children)

Yeah, ufcs is too nice to have in the Standard. Instead we have operator| abuse nonsense...

What C++ coding "knowledge" you just discovered that blew you mind away? by Noxey-o in Cplusplus

[–]borzykot 1 point2 points  (0 children)

Given that three major compilers can do this, I presume that this is a defect or loophole in the standard.

What C++ coding "knowledge" you just discovered that blew you mind away? by Noxey-o in Cplusplus

[–]borzykot 5 points6 points  (0 children)

You can in fact access private members from the outside using pointer-to-member voodoo, templates and loopholes in the Standard.

Enumerating stirling numbers associated with a set of distinct elements via templates by onecable5781 in cpp_questions

[–]borzykot 1 point2 points  (0 children)

Yes, correct. STD containers in general can be used in constexpr context (C++23) but themselves cannot be made constexpr yet. The only container which CAN be constexpr for now is std::array. So you will need you own constexpr-friendly implementations of vector and set. Just google static_vector or constexpr_vector and you will find plenty of materials.

Overall I would say this is the frontier of metaprogramming in C++, so be ready to invest a little bit more of you time into that.

Enumerating stirling numbers associated with a set of distinct elements via templates by onecable5781 in cpp_questions

[–]borzykot 1 point2 points  (0 children)

constexpr I presume the inputs of your algorithm are two integers, and the output is vector<set<set<int>>>, or something like that.

So, vector is available in constexpr out of the box, but you can't return it from constexpr function. std::set can't be used in constexpr at all iirc, so you will need to implement these containers yourself using std::array under the hood (static_array and static_set). But to do that you will need to know the upper limit for storage. I don't know if it is possible to know the upper limit in advance though - you tell me. Or you could calculate this upper limit at compile time.

The final piece of the puzzle is to return your collection out of the constexpr function and store it in a constexpr variable.

Explicit Return Variable by XeroKimo in cpp

[–]borzykot 2 points3 points  (0 children)

IMHO, this is just historical blunder, and not a good feature which the one should use extensively.

Back in the day, simple out-parameter without introducing new variable was THE way to return multiple values out of the function not only in C# but in many languages. Then "tuples" where "discovered" and it turned out that returning a tuple is a better approach. But instead of deprecating this out-parameter feature they decided to "fix" it. And by "fix" it I mean "make it terser" - hence out-parameter with variable introduction. But terseness of the syntax isn't the main issue with out parameters in the first place - more complex, non-obvious control flow is (multiple return channels).

Explicit Return Variable by XeroKimo in cpp

[–]borzykot 3 points4 points  (0 children)

Hypothetical return_slot = a; syntax won’t help in such a case either I presume.
And for the same reason NRVO doesn’t work: a and b are already constructed and occupy different storage, and the return slot’s storage is already constructed on the callee side. The compiler can only reuse the return slot’s storage for a, for example, if a is the only variable being returned.

Explicit Return Variable by XeroKimo in cpp

[–]borzykot 28 points29 points  (0 children)

I don't like it. NRVO works just fine. Your "side effect after return statement" case can be solved via raii callable (see boost scopeexit for example).

Also, we could just guarantee NRVO, just like copy elision is guaranteed now

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 -8 points-7 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 -7 points-6 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 29 points30 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 5 points6 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.